diff --git a/pom.xml b/pom.xml index d57d189e..7117ee33 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,4 @@ - - + - 4.0.0 - maven-plugins org.apache.maven.plugins + maven-plugins 41 - + maven-changes-plugin @@ -55,8 +53,8 @@ under the License. scm:git:https://gitbox.apache.org/repos/asf/maven-changes-plugin.git scm:git:https://gitbox.apache.org/repos/asf/maven-changes-plugin.git - https://github.com/apache/maven-changes-plugin/tree/${project.scm.tag} HEAD + https://github.com/apache/maven-changes-plugin/tree/${project.scm.tag} jira @@ -309,7 +307,7 @@ under the License. - + org.apache.cxf cxf-rt-frontend-jaxrs @@ -436,14 +434,22 @@ under the License. org.codehaus.modello modello-maven-plugin - 1.0.1 + 1.0.1 + + true + 1.0.0 + + src/main/mdo/changes.mdo + + + site-docs - pre-site xdoc + pre-site standard @@ -455,32 +461,25 @@ under the License. generate-xsd - generate-resources xsd + generate-resources ${project.build.outputDirectory}/META-INF/changes/xsd generate-xsd-site - pre-site xsd + pre-site ${project.reporting.outputDirectory}/xsd - - true - 1.0.0 - - src/main/mdo/changes.mdo - - org.codehaus.plexus @@ -502,10 +501,10 @@ under the License. patch-changes-xsd - process-resources execute + process-resources ${project.basedir}/src/main/script/patch-modello.groovy diff --git a/src/main/java/org/apache/maven/plugins/announcement/AbstractAnnouncementMojo.java b/src/main/java/org/apache/maven/plugins/announcement/AbstractAnnouncementMojo.java index 26cd7ac9..0427f810 100644 --- a/src/main/java/org/apache/maven/plugins/announcement/AbstractAnnouncementMojo.java +++ b/src/main/java/org/apache/maven/plugins/announcement/AbstractAnnouncementMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.announcement; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.announcement; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.changes.AbstractChangesMojo; @@ -28,15 +27,13 @@ * @version $Id$ * @since 2.3 */ -public abstract class AbstractAnnouncementMojo - extends AbstractChangesMojo -{ +public abstract class AbstractAnnouncementMojo extends AbstractChangesMojo { /** * This will cause the execution to be run only at the top of a given module tree. That is, run in the project * contained in the same folder where the mvn execution was launched. * * @since 2.3 */ - @Parameter( property = "announcement.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter(property = "announcement.runOnlyAtExecutionRoot", defaultValue = "false") protected boolean runOnlyAtExecutionRoot; } diff --git a/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMailMojo.java b/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMailMojo.java index 62267c8b..9a9ede96 100644 --- a/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMailMojo.java +++ b/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMailMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.announcement; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,10 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.announcement; + +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; import java.io.File; import java.io.FileInputStream; @@ -27,9 +29,6 @@ import java.io.UnsupportedEncodingException; import java.util.List; -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; - import org.apache.maven.model.Developer; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Execute; @@ -51,11 +50,9 @@ * @version $Id$ * @since 2.0-beta-2 */ -@Mojo( name = "announcement-mail", threadSafe = true ) -@Execute( goal = "announcement-generate" ) -public class AnnouncementMailMojo - extends AbstractAnnouncementMojo -{ +@Mojo(name = "announcement-mail", threadSafe = true) +@Execute(goal = "announcement-generate") +public class AnnouncementMailMojo extends AbstractAnnouncementMojo { // ========================================= // announcement-mail goal fields // ========================================= @@ -63,7 +60,7 @@ public class AnnouncementMailMojo /** * Possible senders. */ - @Parameter( property = "project.developers", required = true, readonly = true ) + @Parameter(property = "project.developers", required = true, readonly = true) private List from; /** @@ -71,7 +68,7 @@ public class AnnouncementMailMojo * In this case, this should match the id of one of the developers in the pom. If a matching developer is not found, * then the first developer in the pom will be used. */ - @Parameter( property = "changes.fromDeveloperId" ) + @Parameter(property = "changes.fromDeveloperId") private String fromDeveloperId; /** @@ -79,27 +76,27 @@ public class AnnouncementMailMojo * * @since 2.1 */ - @Parameter( defaultValue = "text/plain", required = true ) + @Parameter(defaultValue = "text/plain", required = true) private String mailContentType; /** * Defines the sender of the announcement email. This takes precedence over the list of developers specified in the * POM. if the sender is not a member of the development team. Note that since this is a bean type, you cannot * specify it from command level with - * + * *
      * -D
      * 
- * + * * . Use - * + * *
      * -Dchanges.sender='Your Name <you@domain>'
      * 
- * + * * instead. */ - @Parameter( property = "changes.mailSender" ) + @Parameter(property = "changes.mailSender") private MailSender mailSender; /** @@ -107,45 +104,45 @@ public class AnnouncementMailMojo * developers in the POM. *

* This parameter parses an email address in standard RFC822 format, e.g. - * + * *

      * -Dchanges.sender='Your Name <you@domain>'
      * 
- * + * * . * * @since 2.7 */ - @Parameter( property = "changes.sender" ) + @Parameter(property = "changes.sender") private String senderString; /** * The password used to send the email. */ - @Parameter( property = "changes.password" ) + @Parameter(property = "changes.password") private String password; /** */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) private MavenProject project; /** * Smtp Server. */ - @Parameter( property = "changes.smtpHost", required = true ) + @Parameter(property = "changes.smtpHost", required = true) private String smtpHost; /** * Port. */ - @Parameter( property = "changes.smtpPort", defaultValue = "25", required = true ) + @Parameter(property = "changes.smtpPort", defaultValue = "25", required = true) private int smtpPort; /** * If the email should be sent in SSL mode. */ - @Parameter( property = "changes.sslMode", defaultValue = "false" ) + @Parameter(property = "changes.sslMode", defaultValue = "false") private boolean sslMode; /** @@ -153,14 +150,17 @@ public class AnnouncementMailMojo * * @since 2.10 */ - @Parameter( property = "changes.startTls", defaultValue = "false" ) + @Parameter(property = "changes.startTls", defaultValue = "false") private boolean startTls; /** * Subject for the email. */ // CHECKSTYLE_OFF: LineLength - @Parameter( property = "changes.subject", defaultValue = "[ANNOUNCEMENT] - ${project.name} ${project.version} released", required = true ) + @Parameter( + property = "changes.subject", + defaultValue = "[ANNOUNCEMENT] - ${project.name} ${project.version} released", + required = true) private String subject; // CHECKSTYLE_ON: LineLength @@ -169,7 +169,7 @@ public class AnnouncementMailMojo * * @since 2.10 */ - @Parameter( property = "changes.announcementFile", defaultValue = "announcement.vm", required = true ) + @Parameter(property = "changes.announcementFile", defaultValue = "announcement.vm", required = true) private String announcementFile; /** @@ -177,7 +177,7 @@ public class AnnouncementMailMojo * * @since 2.10 */ - @Parameter( defaultValue = "${project.build.directory}/announcement", required = true ) + @Parameter(defaultValue = "${project.build.directory}/announcement", required = true) private File announcementDirectory; /** @@ -185,7 +185,7 @@ public class AnnouncementMailMojo * * @since 2.10 */ - @Parameter( property = "changes.templateEncoding", defaultValue = "${project.build.sourceEncoding}" ) + @Parameter(property = "changes.templateEncoding", defaultValue = "${project.build.sourceEncoding}") private String templateEncoding; /** @@ -200,7 +200,7 @@ public class AnnouncementMailMojo /** * Recipient email address. */ - @Parameter( required = true ) + @Parameter(required = true) private List toAddresses; /** @@ -222,71 +222,58 @@ public class AnnouncementMailMojo /** * The username used to send the email. */ - @Parameter( property = "changes.username" ) + @Parameter(property = "changes.username") private String username; private ProjectJavamailMailSender mailer = new ProjectJavamailMailSender(); - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { // Fail build fast if it is using deprecated parameters - if ( templateOutputDirectory != null ) - { - throw new MojoExecutionException( "You are using the old parameter 'templateOutputDirectory'. " - + "You must use 'announcementDirectory' instead." ); + if (templateOutputDirectory != null) { + throw new MojoExecutionException("You are using the old parameter 'templateOutputDirectory'. " + + "You must use 'announcementDirectory' instead."); } // Run only at the execution root - if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) - { - getLog().info( "Skipping the announcement mail in this project because it's not the Execution Root" ); - } - else - { - File file = new File( announcementDirectory, announcementFile ); + if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) { + getLog().info("Skipping the announcement mail in this project because it's not the Execution Root"); + } else { + File file = new File(announcementDirectory, announcementFile); - ConsoleLogger logger = new ConsoleLogger( Logger.LEVEL_INFO, "base" ); + ConsoleLogger logger = new ConsoleLogger(Logger.LEVEL_INFO, "base"); - if ( getLog().isDebugEnabled() ) - { - logger.setThreshold( Logger.LEVEL_DEBUG ); + if (getLog().isDebugEnabled()) { + logger.setThreshold(Logger.LEVEL_DEBUG); } - mailer.enableLogging( logger ); + mailer.enableLogging(logger); - mailer.setSmtpHost( getSmtpHost() ); + mailer.setSmtpHost(getSmtpHost()); - mailer.setSmtpPort( getSmtpPort() ); + mailer.setSmtpPort(getSmtpPort()); - mailer.setSslMode( sslMode, startTls ); + mailer.setSslMode(sslMode, startTls); - if ( username != null ) - { - mailer.setUsername( username ); + if (username != null) { + mailer.setUsername(username); } - if ( password != null ) - { - mailer.setPassword( password ); + if (password != null) { + mailer.setPassword(password); } mailer.initialize(); - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "fromDeveloperId: " + getFromDeveloperId() ); + if (getLog().isDebugEnabled()) { + getLog().debug("fromDeveloperId: " + getFromDeveloperId()); } - if ( file.isFile() ) - { - getLog().info( "Connecting to Host: " + getSmtpHost() + ":" + getSmtpPort() ); + if (file.isFile()) { + getLog().info("Connecting to Host: " + getSmtpHost() + ":" + getSmtpPort()); sendMessage(); - } - else - { - throw new MojoExecutionException( "Announcement file " + file + " not found..." ); + } else { + throw new MojoExecutionException("Announcement file " + file + " not found..."); } } } @@ -296,60 +283,49 @@ public void execute() * * @throws MojoExecutionException if the mail could not be sent */ - protected void sendMessage() - throws MojoExecutionException - { - File file = new File( announcementDirectory, announcementFile ); + protected void sendMessage() throws MojoExecutionException { + File file = new File(announcementDirectory, announcementFile); String email = ""; final MailSender ms = getActualMailSender(); final String fromName = ms.getName(); final String fromAddress = ms.getEmail(); - if ( fromAddress == null || fromAddress.equals( "" ) ) - { - throw new MojoExecutionException( "Invalid mail sender: name and email is mandatory (" + ms + ")." ); + if (fromAddress == null || fromAddress.equals("")) { + throw new MojoExecutionException("Invalid mail sender: name and email is mandatory (" + ms + ")."); } - getLog().info( "Using this sender for email announcement: " + fromAddress + " < " + fromName + " > " ); - try - { + getLog().info("Using this sender for email announcement: " + fromAddress + " < " + fromName + " > "); + try { MailMessage mailMsg = new MailMessage(); - mailMsg.setSubject( getSubject() ); - mailMsg.setContent( readAnnouncement( file ) ); - mailMsg.setContentType( this.mailContentType ); - mailMsg.setFrom( fromAddress, fromName ); + mailMsg.setSubject(getSubject()); + mailMsg.setContent(readAnnouncement(file)); + mailMsg.setContentType(this.mailContentType); + mailMsg.setFrom(fromAddress, fromName); - for ( Object o1 : getToAddresses() ) - { + for (Object o1 : getToAddresses()) { email = o1.toString(); - getLog().info( "Sending mail to " + email + "..." ); - mailMsg.addTo( email, "" ); + getLog().info("Sending mail to " + email + "..."); + mailMsg.addTo(email, ""); } - if ( getCcAddresses() != null ) - { - for ( Object o : getCcAddresses() ) - { + if (getCcAddresses() != null) { + for (Object o : getCcAddresses()) { email = o.toString(); - getLog().info( "Sending cc mail to " + email + "..." ); - mailMsg.addCc( email, "" ); + getLog().info("Sending cc mail to " + email + "..."); + mailMsg.addCc(email, ""); } } - if ( getBccAddresses() != null ) - { - for ( Object o : getBccAddresses() ) - { + if (getBccAddresses() != null) { + for (Object o : getBccAddresses()) { email = o.toString(); - getLog().info( "Sending bcc mail to " + email + "..." ); - mailMsg.addBcc( email, "" ); + getLog().info("Sending bcc mail to " + email + "..."); + mailMsg.addBcc(email, ""); } } - mailer.send( mailMsg ); - getLog().info( "Sent..." ); - } - catch ( MailSenderException e ) - { - throw new MojoExecutionException( "Failed to send email < " + email + " >", e ); + mailer.send(mailMsg); + getLog().info("Sent..."); + } catch (MailSenderException e) { + throw new MojoExecutionException("Failed to send email < " + email + " >", e); } } @@ -360,35 +336,23 @@ protected void sendMessage() * @return Return the announcement text * @throws MojoExecutionException if the file could not be found, or if the encoding is unsupported */ - protected String readAnnouncement( File file ) - throws MojoExecutionException - { - try - { - if ( templateEncoding == null || templateEncoding.isEmpty() ) - { + protected String readAnnouncement(File file) throws MojoExecutionException { + try { + if (templateEncoding == null || templateEncoding.isEmpty()) { templateEncoding = ReaderFactory.FILE_ENCODING; - getLog().warn( "File encoding has not been set, using platform encoding '" + templateEncoding - + "', i.e. build is platform dependent!" ); - + getLog().warn("File encoding has not been set, using platform encoding '" + templateEncoding + + "', i.e. build is platform dependent!"); } - try ( InputStreamReader reader = new InputStreamReader( new FileInputStream( file ), templateEncoding ) ) - { - return IOUtil.toString( reader ); + try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), templateEncoding)) { + return IOUtil.toString(reader); } - } - catch ( FileNotFoundException fnfe ) - { - throw new MojoExecutionException( "File not found. " + file ); - } - catch ( UnsupportedEncodingException uee ) - { - throw new MojoExecutionException( "Unsupported encoding: '" + templateEncoding + "'" ); - } - catch ( IOException ioe ) - { - throw new MojoExecutionException( "Failed to read the announcement file.", ioe ); + } catch (FileNotFoundException fnfe) { + throw new MojoExecutionException("File not found. " + file); + } catch (UnsupportedEncodingException uee) { + throw new MojoExecutionException("Unsupported encoding: '" + templateEncoding + "'"); + } catch (IOException ioe) { + throw new MojoExecutionException("Failed to read the announcement file.", ioe); } } @@ -404,46 +368,31 @@ protected String readAnnouncement( File file ) * @return the mail sender to use * @throws MojoExecutionException if the mail sender could not be retrieved */ - protected MailSender getActualMailSender() - throws MojoExecutionException - { - if ( senderString != null ) - { - try - { - InternetAddress ia = new InternetAddress( senderString, true ); - return new MailSender( ia.getPersonal(), ia.getAddress() ); - } - catch ( AddressException e ) - { - throw new MojoExecutionException( "Invalid value for change.sender: ", e ); + protected MailSender getActualMailSender() throws MojoExecutionException { + if (senderString != null) { + try { + InternetAddress ia = new InternetAddress(senderString, true); + return new MailSender(ia.getPersonal(), ia.getAddress()); + } catch (AddressException e) { + throw new MojoExecutionException("Invalid value for change.sender: ", e); } } - if ( mailSender != null && mailSender.getEmail() != null ) - { + if (mailSender != null && mailSender.getEmail() != null) { return mailSender; - } - else if ( from == null || from.isEmpty() ) - { - throw new MojoExecutionException( "The section in your pom should not be empty. " - + "Add a entry or set the mailSender parameter." ); - } - else if ( fromDeveloperId == null ) - { - final Developer dev = from.get( 0 ); - return new MailSender( dev.getName(), dev.getEmail() ); - } - else - { - for ( Developer developer : from ) - { - if ( fromDeveloperId.equals( developer.getId() ) ) - { - return new MailSender( developer.getName(), developer.getEmail() ); + } else if (from == null || from.isEmpty()) { + throw new MojoExecutionException("The section in your pom should not be empty. " + + "Add a entry or set the mailSender parameter."); + } else if (fromDeveloperId == null) { + final Developer dev = from.get(0); + return new MailSender(dev.getName(), dev.getEmail()); + } else { + for (Developer developer : from) { + if (fromDeveloperId.equals(developer.getId())) { + return new MailSender(developer.getName(), developer.getEmail()); } } - throw new MojoExecutionException( "Missing developer with id '" + fromDeveloperId - + "' in the section in your pom." ); + throw new MojoExecutionException( + "Missing developer with id '" + fromDeveloperId + "' in the section in your pom."); } } @@ -451,163 +400,131 @@ else if ( fromDeveloperId == null ) // announcement-mail accessors // ================================ - public List getBccAddresses() - { + public List getBccAddresses() { return bccAddresses; } - public void setBccAddresses( List bccAddresses ) - { + public void setBccAddresses(List bccAddresses) { this.bccAddresses = bccAddresses; } - public List getCcAddresses() - { + public List getCcAddresses() { return ccAddresses; } - public void setCcAddresses( List ccAddresses ) - { + public void setCcAddresses(List ccAddresses) { this.ccAddresses = ccAddresses; } - public List getFrom() - { + public List getFrom() { return from; } - public void setFrom( List from ) - { + public void setFrom(List from) { this.from = from; } - public String getFromDeveloperId() - { + public String getFromDeveloperId() { return fromDeveloperId; } - public void setFromDeveloperId( String fromDeveloperId ) - { + public void setFromDeveloperId(String fromDeveloperId) { this.fromDeveloperId = fromDeveloperId; } - public MailSender getMailSender() - { + public MailSender getMailSender() { return mailSender; } - public void setMailSender( MailSender mailSender ) - { + public void setMailSender(MailSender mailSender) { this.mailSender = mailSender; } - public String getPassword() - { + public String getPassword() { return password; } - public void setPassword( String password ) - { + public void setPassword(String password) { this.password = password; } - public MavenProject getProject() - { + public MavenProject getProject() { return project; } - public void setProject( MavenProject project ) - { + public void setProject(MavenProject project) { this.project = project; } - public String getSmtpHost() - { + public String getSmtpHost() { return smtpHost; } - public void setSmtpHost( String smtpHost ) - { + public void setSmtpHost(String smtpHost) { this.smtpHost = smtpHost; } - public int getSmtpPort() - { + public int getSmtpPort() { return smtpPort; } - public void setSmtpPort( int smtpPort ) - { + public void setSmtpPort(int smtpPort) { this.smtpPort = smtpPort; } - public boolean isSslMode() - { + public boolean isSslMode() { return sslMode; } - public void setSslMode( boolean sslMode ) - { + public void setSslMode(boolean sslMode) { this.sslMode = sslMode; } - public boolean isStartTls() - { + public boolean isStartTls() { return startTls; } - public void setStartTls( boolean startTls ) - { + public void setStartTls(boolean startTls) { this.startTls = startTls; } - public String getSubject() - { + public String getSubject() { return subject; } - public void setSubject( String subject ) - { + public void setSubject(String subject) { this.subject = subject; } - public String getAnnouncementFile() - { + public String getAnnouncementFile() { return announcementFile; } - public void setAnnouncementFile( String announcementFile ) - { + public void setAnnouncementFile(String announcementFile) { this.announcementFile = announcementFile; } - public File getAnnouncementDirectory() - { + public File getAnnouncementDirectory() { return announcementDirectory; } - public void setAnnouncementDirectory( File announcementDirectory ) - { + public void setAnnouncementDirectory(File announcementDirectory) { this.announcementDirectory = announcementDirectory; } - public List getToAddresses() - { + public List getToAddresses() { return toAddresses; } - public void setToAddresses( List toAddresses ) - { + public void setToAddresses(List toAddresses) { this.toAddresses = toAddresses; } - public String getUsername() - { + public String getUsername() { return username; } - public void setUsername( String username ) - { + public void setUsername(String username) { this.username = username; } } diff --git a/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMojo.java b/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMojo.java index ea5fe139..a2aa13ad 100644 --- a/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMojo.java +++ b/src/main/java/org/apache/maven/plugins/announcement/AnnouncementMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.announcement; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.announcement; import java.io.File; import java.io.FileOutputStream; @@ -67,10 +66,8 @@ * @version $Id$ * @since 2.0-beta-2 */ -@Mojo( name = "announcement-generate", threadSafe = true ) -public class AnnouncementMojo - extends AbstractAnnouncementMojo -{ +@Mojo(name = "announcement-generate", threadSafe = true) +public class AnnouncementMojo extends AbstractAnnouncementMojo { private static final String CHANGES_XML = "changes.xml"; private static final String JIRA = "JIRA"; @@ -85,7 +82,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( property = "changes.announcementFile" ) + @Parameter(property = "changes.announcementFile") private String announcementFile; /** @@ -98,30 +95,30 @@ public class AnnouncementMojo /** */ - @Parameter( property = "project.artifactId", readonly = true ) + @Parameter(property = "project.artifactId", readonly = true) private String artifactId; /** * Name of the team that develops the artifact. This parameter will be passed to the template. */ - @Parameter( property = "changes.developmentTeam", defaultValue = "${project.name} team", required = true ) + @Parameter(property = "changes.developmentTeam", defaultValue = "${project.name} team", required = true) private String developmentTeam; /** * The name of the artifact to be used in the announcement. */ - @Parameter( property = "changes.finalName", defaultValue = "${project.build.finalName}", required = true ) + @Parameter(property = "changes.finalName", defaultValue = "${project.build.finalName}", required = true) private String finalName; /** */ - @Parameter( property = "project.groupId", readonly = true ) + @Parameter(property = "project.groupId", readonly = true) private String groupId; /** * Short description or introduction of the released artifact. This parameter will be passed to the template. */ - @Parameter( defaultValue = "${project.description}" ) + @Parameter(defaultValue = "${project.description}") private String introduction; /** @@ -156,7 +153,7 @@ public class AnnouncementMojo * * @since 2.10 */ - @Parameter( defaultValue = "${project.build.directory}/announcement", required = true ) + @Parameter(defaultValue = "${project.build.directory}/announcement", required = true) private File announcementDirectory; /** @@ -171,19 +168,19 @@ public class AnnouncementMojo /** * Packaging structure for the artifact. */ - @Parameter( property = "project.packaging", readonly = true ) + @Parameter(property = "project.packaging", readonly = true) private String packaging; /** * The Maven Project. */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) private MavenProject project; /** * The Velocity template used to format the announcement. */ - @Parameter( property = "changes.template", defaultValue = "announcement.vm", required = true ) + @Parameter(property = "changes.template", defaultValue = "announcement.vm", required = true) private String template; /** @@ -194,7 +191,10 @@ public class AnnouncementMojo *

*/ // CHECKSTYLE_OFF: LineLength - @Parameter( property = "changes.templateDirectory", defaultValue = "org/apache/maven/plugins/announcement", required = true ) + @Parameter( + property = "changes.templateDirectory", + defaultValue = "org/apache/maven/plugins/announcement", + required = true) private String templateDirectory; // CHECKSTYLE_ON: LineLength @@ -203,7 +203,7 @@ public class AnnouncementMojo * * @since 2.1 */ - @Parameter( property = "changes.templateEncoding", defaultValue = "${project.build.sourceEncoding}" ) + @Parameter(property = "changes.templateEncoding", defaultValue = "${project.build.sourceEncoding}") private String templateEncoding; /** @@ -213,13 +213,13 @@ public class AnnouncementMojo * * @since 2.10 */ - @Parameter( property = "changes.useJql", defaultValue = "false" ) + @Parameter(property = "changes.useJql", defaultValue = "false") private boolean useJql; /** * Distribution URL of the artifact. This parameter will be passed to the template. */ - @Parameter( property = "project.url" ) + @Parameter(property = "project.url") private String url; /** @@ -232,7 +232,7 @@ public class AnnouncementMojo /** * Velocity Component. */ - @Component( role = VelocityComponent.class, hint = "maven-changes-plugin" ) + @Component(role = VelocityComponent.class, hint = "maven-changes-plugin") private VelocityComponent velocity; /** @@ -244,7 +244,7 @@ public class AnnouncementMojo /** * Version of the artifact. */ - @Parameter( property = "changes.version", defaultValue = "${project.version}", required = true ) + @Parameter(property = "changes.version", defaultValue = "${project.version}", required = true) private String version; /** @@ -253,7 +253,7 @@ public class AnnouncementMojo * @parameter expression="${basedir}/src/changes/changes.xml" * @required */ - @Parameter( defaultValue = "${basedir}/src/changes/changes.xml" ) + @Parameter(defaultValue = "${basedir}/src/changes/changes.xml") private File xmlPath; // =======================================// @@ -275,7 +275,7 @@ public class AnnouncementMojo * @deprecated Since version 2.4 this parameter has been deprecated. Please use the issueManagementSystems parameter * instead. */ - @Parameter( property = "generateJiraAnnouncement" ) + @Parameter(property = "generateJiraAnnouncement") private Boolean generateJiraAnnouncement; /** @@ -285,7 +285,7 @@ public class AnnouncementMojo * @deprecated Since version 2.4 this parameter has been deprecated. Please use the issueManagementSystems parameter * instead. */ - @Parameter( property = "changes.jiraMerge" ) + @Parameter(property = "changes.jiraMerge") private Boolean jiraMerge; /** @@ -293,7 +293,7 @@ public class AnnouncementMojo * * @since 2.1 */ - @Parameter( property = "changes.jiraPassword" ) + @Parameter(property = "changes.jiraPassword") private String jiraPassword; /** @@ -301,7 +301,7 @@ public class AnnouncementMojo * * @since 2.1 */ - @Parameter( property = "changes.jiraUser" ) + @Parameter(property = "changes.jiraUser") private String jiraUser; /** @@ -309,13 +309,13 @@ public class AnnouncementMojo * * @since 3.0.0 */ - @Parameter( property = "changes.jiraServerId" ) + @Parameter(property = "changes.jiraServerId") private String jiraServerId; /** * Path to the JIRA XML file, which will be parsed. */ - @Parameter( defaultValue = "${project.build.directory}/jira-announcement.xml", required = true, readonly = true ) + @Parameter(defaultValue = "${project.build.directory}/jira-announcement.xml", required = true, readonly = true) private File jiraXML; /** @@ -324,7 +324,7 @@ public class AnnouncementMojo * Note: In versions 2.0-beta-3 and earlier this parameter was called "nbEntries". *

*/ - @Parameter( property = "changes.maxEntries", defaultValue = "25", required = true ) + @Parameter(property = "changes.maxEntries", defaultValue = "25", required = true) private int maxEntries; /** @@ -334,13 +334,13 @@ public class AnnouncementMojo * Note: In versions 2.0-beta-3 and earlier this parameter was called "resolutionId". *

*/ - @Parameter( property = "changes.resolutionIds", defaultValue = "Fixed" ) + @Parameter(property = "changes.resolutionIds", defaultValue = "Fixed") private String resolutionIds; /** * Settings XML configuration. */ - @Parameter( defaultValue = "${settings}", readonly = true, required = true ) + @Parameter(defaultValue = "${settings}", readonly = true, required = true) private Settings settings; /** @@ -350,7 +350,7 @@ public class AnnouncementMojo * Note: In versions 2.0-beta-3 and earlier this parameter was called "statusId". *

*/ - @Parameter( property = "changes.statusIds", defaultValue = "Closed" ) + @Parameter(property = "changes.statusIds", defaultValue = "Closed") private String statusIds; /** @@ -358,7 +358,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( property = "changes.webUser" ) + @Parameter(property = "changes.webUser") private String webUser; /** @@ -366,7 +366,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( property = "changes.webPassword" ) + @Parameter(property = "changes.webPassword") private String webPassword; /** @@ -379,7 +379,7 @@ public class AnnouncementMojo * * @since 2.5 */ - @Parameter( property = "changes.versionPrefix" ) + @Parameter(property = "changes.versionPrefix") private String versionPrefix; /** @@ -390,7 +390,7 @@ public class AnnouncementMojo * * @since 2.11 */ - @Parameter( property = "changes.jiraConnectionTimeout", defaultValue = "36000" ) + @Parameter(property = "changes.jiraConnectionTimeout", defaultValue = "36000") private int jiraConnectionTimeout; /** @@ -401,7 +401,7 @@ public class AnnouncementMojo * * @since 2.11 */ - @Parameter( property = "changes.jiraReceiveTimout", defaultValue = "32000" ) + @Parameter(property = "changes.jiraReceiveTimout", defaultValue = "32000") private int jiraReceiveTimout; // =======================================// @@ -413,7 +413,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( property = "changes.tracPassword" ) + @Parameter(property = "changes.tracPassword") private String tracPassword; /** @@ -421,7 +421,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( defaultValue = "order=id" ) + @Parameter(defaultValue = "order=id") private String tracQuery; /** @@ -429,7 +429,7 @@ public class AnnouncementMojo * * @since 2.4 */ - @Parameter( property = "changes.tracUser" ) + @Parameter(property = "changes.tracUser") private String tracUser; // =======================================// @@ -438,18 +438,18 @@ public class AnnouncementMojo /** * The scheme of your github api domain. Only use if using github enterprise. - * + * * @since 2.9 */ - @Parameter( defaultValue = "http", property = "changes.githubAPIScheme" ) + @Parameter(defaultValue = "http", property = "changes.githubAPIScheme") private String githubAPIScheme; /** * The port of your github api domain. Only use if using github enterprise. - * + * * @since 2.9 */ - @Parameter( defaultValue = "80", property = "changes.githubAPIPort" ) + @Parameter(defaultValue = "80", property = "changes.githubAPIPort") private int githubAPIPort; /** @@ -458,16 +458,16 @@ public class AnnouncementMojo * * @since 2.12 */ - @Parameter( defaultValue = "github" ) + @Parameter(defaultValue = "github") private String githubAPIServerId; /** * Boolean which says if we should include open github issues in the announcement. */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean includeOpenIssues; - private ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); + private ReleaseUtils releaseUtils = new ReleaseUtils(getLog()); private ChangesXML xml; @@ -480,94 +480,70 @@ public class AnnouncementMojo * * @throws MojoExecutionException in case of errors */ - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { // Fail build fast if it is using deprecated parameters - failIfUsingDeprecatedParameter( outputDirectory, "outputDirectory", "announcementDirectory" ); - failIfUsingDeprecatedParameter( generateJiraAnnouncement, "generateJiraAnnouncement", - "issueManagementSystems " ); - failIfUsingDeprecatedParameter( jiraMerge, "jiraMerge", "issueManagementSystems " ); + failIfUsingDeprecatedParameter(outputDirectory, "outputDirectory", "announcementDirectory"); + failIfUsingDeprecatedParameter(generateJiraAnnouncement, "generateJiraAnnouncement", "issueManagementSystems "); + failIfUsingDeprecatedParameter(jiraMerge, "jiraMerge", "issueManagementSystems "); // Run only at the execution root - if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) - { - getLog().info( "Skipping the announcement generation in this project because it's not the Execution Root" ); - } - else - { - if ( issueManagementSystems == null ) - { + if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) { + getLog().info("Skipping the announcement generation in this project because it's not the Execution Root"); + } else { + if (issueManagementSystems == null) { issueManagementSystems = new ArrayList<>(); } - if ( issueManagementSystems.isEmpty() ) - { - issueManagementSystems.add( CHANGES_XML ); + if (issueManagementSystems.isEmpty()) { + issueManagementSystems.add(CHANGES_XML); } // Fetch releases from the configured issue management systems List releases = null; - if ( issueManagementSystems.contains( CHANGES_XML ) ) - { - if ( getXmlPath().exists() ) - { - ChangesXML changesXML = new ChangesXML( getXmlPath(), getLog() ); + if (issueManagementSystems.contains(CHANGES_XML)) { + if (getXmlPath().exists()) { + ChangesXML changesXML = new ChangesXML(getXmlPath(), getLog()); List changesReleases = changesXML.getReleaseList(); - releases = releaseUtils.mergeReleases( null, changesReleases ); - getLog().info( "Including issues from file " + getXmlPath() + " in announcement..." ); - } - else - { - getLog().warn( "changes.xml file " + getXmlPath().getAbsolutePath() + " does not exist." ); + releases = releaseUtils.mergeReleases(null, changesReleases); + getLog().info("Including issues from file " + getXmlPath() + " in announcement..."); + } else { + getLog().warn("changes.xml file " + getXmlPath().getAbsolutePath() + " does not exist."); } } - if ( issueManagementSystems.contains( JIRA ) ) - { - String message = ProjectUtils.validateIssueManagement( project, JIRA, "JIRA announcement" ); - if ( message == null ) - { + if (issueManagementSystems.contains(JIRA)) { + String message = ProjectUtils.validateIssueManagement(project, JIRA, "JIRA announcement"); + if (message == null) { List jiraReleases = getJiraReleases(); - releases = releaseUtils.mergeReleases( releases, jiraReleases ); - getLog().info( "Including issues from JIRA in announcement..." ); - } - else - { - throw new MojoExecutionException( "Something is wrong with the Issue Management section. " - + message ); + releases = releaseUtils.mergeReleases(releases, jiraReleases); + getLog().info("Including issues from JIRA in announcement..."); + } else { + throw new MojoExecutionException( + "Something is wrong with the Issue Management section. " + message); } } - if ( issueManagementSystems.contains( TRAC ) ) - { - String message = ProjectUtils.validateIssueManagement( project, TRAC, "Trac announcement" ); - if ( message == null ) - { + if (issueManagementSystems.contains(TRAC)) { + String message = ProjectUtils.validateIssueManagement(project, TRAC, "Trac announcement"); + if (message == null) { List tracReleases = getTracReleases(); - releases = releaseUtils.mergeReleases( releases, tracReleases ); - getLog().info( "Including issues from Trac in announcement..." ); - } - else - { - throw new MojoExecutionException( "Something is wrong with the Issue Management section. " - + message ); + releases = releaseUtils.mergeReleases(releases, tracReleases); + getLog().info("Including issues from Trac in announcement..."); + } else { + throw new MojoExecutionException( + "Something is wrong with the Issue Management section. " + message); } } - if ( issueManagementSystems.contains( GIT_HUB ) ) - { - String message = ProjectUtils.validateIssueManagement( project, GIT_HUB, "GitHub announcement" ); - if ( message == null ) - { + if (issueManagementSystems.contains(GIT_HUB)) { + String message = ProjectUtils.validateIssueManagement(project, GIT_HUB, "GitHub announcement"); + if (message == null) { List gitHubReleases = getGitHubReleases(); - releases = releaseUtils.mergeReleases( releases, gitHubReleases ); - getLog().info( "Including issues from GitHub in announcement..." ); - } - else - { - throw new MojoExecutionException( "Something is wrong with the Issue Management section. " - + message ); + releases = releaseUtils.mergeReleases(releases, gitHubReleases); + getLog().info("Including issues from GitHub in announcement..."); + } else { + throw new MojoExecutionException( + "Something is wrong with the Issue Management section. " + message); } } @@ -581,25 +557,20 @@ public void execute() // For help with these steps, you can have a look at how this has been done for JIRA or Trac // Generate the report - if ( releases == null || releases.isEmpty() ) - { - throw new MojoExecutionException( "No releases found in any of the " - + "configured issue management systems." ); - } - else - { - doGenerate( releases ); + if (releases == null || releases.isEmpty()) { + throw new MojoExecutionException( + "No releases found in any of the " + "configured issue management systems."); + } else { + doGenerate(releases); } } } - private void failIfUsingDeprecatedParameter( Object value, String name, String replacement ) - throws MojoExecutionException - { - if ( value != null ) - { - throw new MojoExecutionException( "You are using the old parameter '" + name + "'. " + "You must use '" - + replacement + "' instead." ); + private void failIfUsingDeprecatedParameter(Object value, String name, String replacement) + throws MojoExecutionException { + if (value != null) { + throw new MojoExecutionException( + "You are using the old parameter '" + name + "'. " + "You must use '" + replacement + "' instead."); } } @@ -609,73 +580,60 @@ private void failIfUsingDeprecatedParameter( Object value, String name, String r * @param releases A List of Releases * @throws MojoExecutionException in case of errors */ - public void doGenerate( List releases ) - throws MojoExecutionException - { - String version = ( versionPrefix == null ? "" : versionPrefix ) + getVersion(); + public void doGenerate(List releases) throws MojoExecutionException { + String version = (versionPrefix == null ? "" : versionPrefix) + getVersion(); - getLog().debug( "Generating announcement for version [" + version + "]. Found these releases: " - + ReleaseUtils.toString( releases ) ); + getLog().debug("Generating announcement for version [" + version + "]. Found these releases: " + + ReleaseUtils.toString(releases)); - doGenerate( releases, releaseUtils.getLatestRelease( releases, version ) ); + doGenerate(releases, releaseUtils.getLatestRelease(releases, version)); } - protected void doGenerate( List releases, Release release ) - throws MojoExecutionException - { - try - { - ToolManager toolManager = new ToolManager( true ); + protected void doGenerate(List releases, Release release) throws MojoExecutionException { + try { + ToolManager toolManager = new ToolManager(true); Context context = toolManager.createContext(); - if ( getIntroduction() == null || getIntroduction().equals( "" ) ) - { - setIntroduction( getUrl() ); + if (getIntroduction() == null || getIntroduction().equals("")) { + setIntroduction(getUrl()); } - context.put( "releases", releases ); + context.put("releases", releases); - context.put( "groupId", getGroupId() ); + context.put("groupId", getGroupId()); - context.put( "artifactId", getArtifactId() ); + context.put("artifactId", getArtifactId()); - context.put( "version", getVersion() ); + context.put("version", getVersion()); - context.put( "packaging", getPackaging() ); + context.put("packaging", getPackaging()); - context.put( "url", getUrl() ); + context.put("url", getUrl()); - context.put( "release", release ); + context.put("release", release); - context.put( "introduction", getIntroduction() ); + context.put("introduction", getIntroduction()); - context.put( "developmentTeam", getDevelopmentTeam() ); + context.put("developmentTeam", getDevelopmentTeam()); - context.put( "finalName", getFinalName() ); + context.put("finalName", getFinalName()); - context.put( "urlDownload", getUrlDownload() ); + context.put("urlDownload", getUrlDownload()); - context.put( "project", project ); + context.put("project", project); - if ( announceParameters == null ) - { + if (announceParameters == null) { // empty Map to prevent NPE in velocity execution - context.put( "announceParameters", Collections.emptyMap() ); - } - else - { - context.put( "announceParameters", announceParameters ); + context.put("announceParameters", Collections.emptyMap()); + } else { + context.put("announceParameters", announceParameters); } - processTemplate( context, announcementDirectory, template, announcementFile ); - } - catch ( ResourceNotFoundException rnfe ) - { - throw new MojoExecutionException( "Resource not found.", rnfe ); - } - catch ( VelocityException ve ) - { - throw new MojoExecutionException( ve.toString(), ve ); + processTemplate(context, announcementDirectory, template, announcementFile); + } catch (ResourceNotFoundException rnfe) { + throw new MojoExecutionException("Resource not found.", rnfe); + } catch (VelocityException ve) { + throw new MojoExecutionException(ve.toString(), ve); } } @@ -689,192 +647,153 @@ protected void doGenerate( List releases, Release release ) * @throws VelocityException in case of errors. * @throws MojoExecutionException in case of errors. */ - public void processTemplate( Context context, File outputDirectory, String template, String announcementFile ) - throws VelocityException, MojoExecutionException - { + public void processTemplate(Context context, File outputDirectory, String template, String announcementFile) + throws VelocityException, MojoExecutionException { File f; // Use the name of the template as a default value - if ( announcementFile == null || announcementFile.isEmpty() ) - { + if (announcementFile == null || announcementFile.isEmpty()) { announcementFile = template; } - try - { - f = new File( outputDirectory, announcementFile ); + try { + f = new File(outputDirectory, announcementFile); - if ( !f.getParentFile().exists() ) - { + if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } VelocityEngine engine = velocity.getEngine(); - engine.setApplicationAttribute( "baseDirectory", basedir ); + engine.setApplicationAttribute("baseDirectory", basedir); - if ( templateEncoding == null || templateEncoding.isEmpty() ) - { + if (templateEncoding == null || templateEncoding.isEmpty()) { templateEncoding = ReaderFactory.FILE_ENCODING; - getLog().warn( "File encoding has not been set, using platform encoding " + templateEncoding - + ", i.e. build is platform dependent!" ); + getLog().warn("File encoding has not been set, using platform encoding " + templateEncoding + + ", i.e. build is platform dependent!"); } - Writer writer = new OutputStreamWriter( new FileOutputStream( f ), templateEncoding ); + Writer writer = new OutputStreamWriter(new FileOutputStream(f), templateEncoding); - Template velocityTemplate = engine.getTemplate( templateDirectory + "/" + template, templateEncoding ); + Template velocityTemplate = engine.getTemplate(templateDirectory + "/" + template, templateEncoding); - velocityTemplate.merge( context, writer ); + velocityTemplate.merge(context, writer); writer.flush(); writer.close(); - getLog().info( "Created template " + f ); - } - - catch ( ResourceNotFoundException rnfe ) - { - throw new ResourceNotFoundException( "Template not found. ( " + templateDirectory + "/" + template + " )" ); - } - catch ( VelocityException ve ) - { - throw new VelocityException( ve.toString() ); - } - - catch ( Exception e ) - { - if ( e.getCause() != null ) - { - getLog().warn( e.getCause() ); + getLog().info("Created template " + f); + } catch (ResourceNotFoundException rnfe) { + throw new ResourceNotFoundException("Template not found. ( " + templateDirectory + "/" + template + " )"); + } catch (VelocityException ve) { + throw new VelocityException(ve.toString()); + } catch (Exception e) { + if (e.getCause() != null) { + getLog().warn(e.getCause()); } - throw new MojoExecutionException( e.toString(), e.getCause() ); + throw new MojoExecutionException(e.toString(), e.getCause()); } } - protected List getJiraReleases() - throws MojoExecutionException - { + protected List getJiraReleases() throws MojoExecutionException { AbstractJiraDownloader jiraDownloader = new AdaptiveJiraDownloader(); File jiraXMLFile = jiraXML; - jiraDownloader.setLog( getLog() ); + jiraDownloader.setLog(getLog()); - jiraDownloader.setOutput( jiraXMLFile ); + jiraDownloader.setOutput(jiraXMLFile); - jiraDownloader.setStatusIds( statusIds ); + jiraDownloader.setStatusIds(statusIds); - jiraDownloader.setResolutionIds( resolutionIds ); + jiraDownloader.setResolutionIds(resolutionIds); - jiraDownloader.setMavenProject( project ); + jiraDownloader.setMavenProject(project); - jiraDownloader.setSettings( settings ); + jiraDownloader.setSettings(settings); - jiraDownloader.setNbEntries( maxEntries ); + jiraDownloader.setNbEntries(maxEntries); - jiraDownloader.setFilter( filter ); + jiraDownloader.setFilter(filter); - if ( jiraServerId != null ) - { - final Server server = mavenSession.getSettings().getServer( jiraServerId ); - jiraDownloader.setJiraUser( server.getUsername() ); - jiraDownloader.setJiraPassword( server.getPassword() ); - } - else - { - jiraDownloader.setJiraUser( jiraUser ); - jiraDownloader.setJiraPassword( jiraPassword ); + if (jiraServerId != null) { + final Server server = mavenSession.getSettings().getServer(jiraServerId); + jiraDownloader.setJiraUser(server.getUsername()); + jiraDownloader.setJiraPassword(server.getPassword()); + } else { + jiraDownloader.setJiraUser(jiraUser); + jiraDownloader.setJiraPassword(jiraPassword); } - jiraDownloader.setUseJql( useJql ); + jiraDownloader.setUseJql(useJql); - jiraDownloader.setWebUser( webUser ); + jiraDownloader.setWebUser(webUser); - jiraDownloader.setWebPassword( webPassword ); + jiraDownloader.setWebPassword(webPassword); - jiraDownloader.setConnectionTimeout( jiraConnectionTimeout ); + jiraDownloader.setConnectionTimeout(jiraConnectionTimeout); - jiraDownloader.setReceiveTimout( jiraReceiveTimout ); + jiraDownloader.setReceiveTimout(jiraReceiveTimout); - try - { + try { jiraDownloader.doExecute(); List issueList = jiraDownloader.getIssueList(); - if ( versionPrefix != null && !versionPrefix.isEmpty() ) - { + if (versionPrefix != null && !versionPrefix.isEmpty()) { int originalNumberOfIssues = issueList.size(); - issueList = IssueUtils.filterIssuesWithVersionPrefix( issueList, versionPrefix ); - getLog().debug( "Filtered out " + issueList.size() + " issues of " + originalNumberOfIssues - + " that matched the versionPrefix '" + versionPrefix + "'." ); + issueList = IssueUtils.filterIssuesWithVersionPrefix(issueList, versionPrefix); + getLog().debug("Filtered out " + issueList.size() + " issues of " + originalNumberOfIssues + + " that matched the versionPrefix '" + versionPrefix + "'."); } - return getReleases( issueList, new JIRAIssueManagmentSystem() ); - } - catch ( Exception e ) - { - throw new MojoExecutionException( "Failed to extract issues from JIRA.", e ); + return getReleases(issueList, new JIRAIssueManagmentSystem()); + } catch (Exception e) { + throw new MojoExecutionException("Failed to extract issues from JIRA.", e); } } - private List getReleases( List issues, IssueManagementSystem ims ) - throws MojoExecutionException - { - if ( issueTypes != null ) - { - ims.applyConfiguration( issueTypes ); + private List getReleases(List issues, IssueManagementSystem ims) throws MojoExecutionException { + if (issueTypes != null) { + ims.applyConfiguration(issueTypes); } - if ( issues.isEmpty() ) - { + if (issues.isEmpty()) { return Collections.emptyList(); - } - else - { - IssueAdapter adapter = new IssueAdapter( ims ); - return adapter.getReleases( issues ); + } else { + IssueAdapter adapter = new IssueAdapter(ims); + return adapter.getReleases(issues); } } - protected List getTracReleases() - throws MojoExecutionException - { + protected List getTracReleases() throws MojoExecutionException { TracDownloader issueDownloader = new TracDownloader(); - issueDownloader.setProject( project ); + issueDownloader.setProject(project); - issueDownloader.setQuery( tracQuery ); + issueDownloader.setQuery(tracQuery); - issueDownloader.setTracPassword( tracPassword ); + issueDownloader.setTracPassword(tracPassword); - issueDownloader.setTracUser( tracUser ); + issueDownloader.setTracUser(tracUser); - try - { - return getReleases( issueDownloader.getIssueList(), new TracIssueManagmentSystem() ); - } - catch ( Exception e ) - { - throw new MojoExecutionException( "Failed to extract issues from Trac.", e ); + try { + return getReleases(issueDownloader.getIssueList(), new TracIssueManagmentSystem()); + } catch (Exception e) { + throw new MojoExecutionException("Failed to extract issues from Trac.", e); } } - protected List getGitHubReleases() - throws MojoExecutionException - { - try - { + protected List getGitHubReleases() throws MojoExecutionException { + try { GitHubDownloader issueDownloader = - new GitHubDownloader( project, githubAPIScheme, githubAPIPort, includeOpenIssues, true ); + new GitHubDownloader(project, githubAPIScheme, githubAPIPort, includeOpenIssues, true); - issueDownloader.configureAuthentication( settingsDecrypter, githubAPIServerId, settings, getLog() ); + issueDownloader.configureAuthentication(settingsDecrypter, githubAPIServerId, settings, getLog()); - return getReleases( issueDownloader.getIssueList(), new GitHubIssueManagementSystem() ); - } - catch ( Exception e ) - { - throw new MojoExecutionException( "Failed to extract issues from GitHub.", e ); + return getReleases(issueDownloader.getIssueList(), new GitHubIssueManagementSystem()); + } catch (Exception e) { + throw new MojoExecutionException("Failed to extract issues from GitHub.", e); } } @@ -882,143 +801,115 @@ protected List getGitHubReleases() * accessors */ - public String getArtifactId() - { + public String getArtifactId() { return artifactId; } - public void setArtifactId( String artifactId ) - { + public void setArtifactId(String artifactId) { this.artifactId = artifactId; } - public String getDevelopmentTeam() - { + public String getDevelopmentTeam() { return developmentTeam; } - public void setDevelopmentTeam( String developmentTeam ) - { + public void setDevelopmentTeam(String developmentTeam) { this.developmentTeam = developmentTeam; } - public String getFinalName() - { + public String getFinalName() { return finalName; } - public void setFinalName( String finalName ) - { + public void setFinalName(String finalName) { this.finalName = finalName; } - public String getGroupId() - { + public String getGroupId() { return groupId; } - public void setGroupId( String groupId ) - { + public void setGroupId(String groupId) { this.groupId = groupId; } - public String getIntroduction() - { + public String getIntroduction() { return introduction; } - public void setIntroduction( String introduction ) - { + public void setIntroduction(String introduction) { this.introduction = introduction; } - public void setIssueTypes( Map issueTypes ) - { + public void setIssueTypes(Map issueTypes) { this.issueTypes = issueTypes; } - public Map getIssueTypes() - { + public Map getIssueTypes() { return issueTypes; } - public File getAnnouncementDirectory() - { + public File getAnnouncementDirectory() { return announcementDirectory; } - public void setAnnouncementDirectory( File announcementDirectory ) - { + public void setAnnouncementDirectory(File announcementDirectory) { this.announcementDirectory = announcementDirectory; } - public String getPackaging() - { + public String getPackaging() { return packaging; } - public void setPackaging( String packaging ) - { + public void setPackaging(String packaging) { this.packaging = packaging; } - public String getUrl() - { + public String getUrl() { return url; } - public void setUrl( String url ) - { + public void setUrl(String url) { this.url = url; } - public String getUrlDownload() - { + public String getUrlDownload() { return urlDownload; } - public void setUrlDownload( String urlDownload ) - { + public void setUrlDownload(String urlDownload) { this.urlDownload = urlDownload; } - public VelocityComponent getVelocity() - { + public VelocityComponent getVelocity() { return velocity; } - public void setVelocity( VelocityComponent velocity ) - { + public void setVelocity(VelocityComponent velocity) { this.velocity = velocity; } - public String getVersion() - { + public String getVersion() { return version; } - public void setVersion( String version ) - { + public void setVersion(String version) { this.version = version; } - public ChangesXML getXml() - { + public ChangesXML getXml() { return xml; } - public void setXml( ChangesXML xml ) - { + public void setXml(ChangesXML xml) { this.xml = xml; } - public File getXmlPath() - { + public File getXmlPath() { return xmlPath; } - public void setXmlPath( File xmlPath ) - { + public void setXmlPath(File xmlPath) { this.xmlPath = xmlPath; } } diff --git a/src/main/java/org/apache/maven/plugins/announcement/MailSender.java b/src/main/java/org/apache/maven/plugins/announcement/MailSender.java index bfb5eaab..6e25d9fc 100644 --- a/src/main/java/org/apache/maven/plugins/announcement/MailSender.java +++ b/src/main/java/org/apache/maven/plugins/announcement/MailSender.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.announcement; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.announcement; /** * Defines the sender of the announcement if the list of developer is empty or if the sender is not a member of the @@ -25,46 +24,38 @@ * * @author Stephane Nicoll */ -public class MailSender -{ +public class MailSender { private String name; private String email; - public MailSender() - { + public MailSender() { super(); } - public MailSender( String name, String email ) - { + public MailSender(String name, String email) { this.name = name; this.email = email; } - public String getName() - { + public String getName() { return name; } - public void setName( String name ) - { + public void setName(String name) { this.name = name; } - public String getEmail() - { + public String getEmail() { return email; } - public void setEmail( String email ) - { + public void setEmail(String email) { this.email = email; } - public String toString() - { + public String toString() { return getName() + " (" + getEmail() + ")"; } } diff --git a/src/main/java/org/apache/maven/plugins/announcement/mailsender/ProjectJavamailMailSender.java b/src/main/java/org/apache/maven/plugins/announcement/mailsender/ProjectJavamailMailSender.java index a95414df..0b73b5de 100644 --- a/src/main/java/org/apache/maven/plugins/announcement/mailsender/ProjectJavamailMailSender.java +++ b/src/main/java/org/apache/maven/plugins/announcement/mailsender/ProjectJavamailMailSender.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.announcement.mailsender; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ - -import java.util.Date; -import java.util.Properties; +package org.apache.maven.plugins.announcement.mailsender; import javax.mail.Authenticator; import javax.mail.Message; @@ -31,6 +27,9 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; +import java.util.Date; +import java.util.Properties; + import org.codehaus.plexus.mailsender.AbstractMailSender; import org.codehaus.plexus.mailsender.MailMessage; import org.codehaus.plexus.mailsender.MailSenderException; @@ -40,9 +39,7 @@ /** * Helper class for sending email. */ -public class ProjectJavamailMailSender - extends AbstractMailSender -{ +public class ProjectJavamailMailSender extends AbstractMailSender { private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; // ---------------------------------------------------------------------- @@ -57,54 +54,46 @@ public class ProjectJavamailMailSender // Component Lifecycle // ---------------------------------------------------------------------- - public void initialize() - { - if ( StringUtils.isEmpty( getSmtpHost() ) ) - { - System.out.println( "Error in configuration: Missing smtpHost." ); + public void initialize() { + if (StringUtils.isEmpty(getSmtpHost())) { + System.out.println("Error in configuration: Missing smtpHost."); } - if ( getSmtpPort() == 0 ) - { - setSmtpPort( DEFAULT_SMTP_PORT ); + if (getSmtpPort() == 0) { + setSmtpPort(DEFAULT_SMTP_PORT); } props = new Properties(); - props.put( "mail.smtp.host", getSmtpHost() ); + props.put("mail.smtp.host", getSmtpHost()); - props.put( "mail.smtp.port", String.valueOf( getSmtpPort() ) ); + props.put("mail.smtp.port", String.valueOf(getSmtpPort())); - if ( getUsername() != null ) - { - props.put( "mail.smtp.auth", "true" ); + if (getUsername() != null) { + props.put("mail.smtp.auth", "true"); } - props.put( "mail.debug", String.valueOf( getLogger().isDebugEnabled() ) ); + props.put("mail.debug", String.valueOf(getLogger().isDebugEnabled())); - if ( isSslMode() ) - { - props.put( "mail.smtp.socketFactory.port", String.valueOf( getSmtpPort() ) ); + if (isSslMode()) { + props.put("mail.smtp.socketFactory.port", String.valueOf(getSmtpPort())); - props.put( "mail.smtp.socketFactory.class", SSL_FACTORY ); + props.put("mail.smtp.socketFactory.class", SSL_FACTORY); - props.put( "mail.smtp.socketFactory.fallback", "false" ); - } + props.put("mail.smtp.socketFactory.fallback", "false"); + } - if ( isTlsEnabled() ) - { - props.put( "mail.smtp.starttls.enable", "true" ); + if (isTlsEnabled()) { + props.put("mail.smtp.starttls.enable", "true"); } - if ( userProperties != null ) - { - for ( Object o : userProperties.keySet() ) - { + if (userProperties != null) { + for (Object o : userProperties.keySet()) { String key = (String) o; - String value = userProperties.getProperty( key ); + String value = userProperties.getProperty(key); - props.put( key, value ); + props.put(key, value); } } } @@ -113,89 +102,75 @@ public void initialize() // MailSender Implementation // ---------------------------------------------------------------------- - public void send( MailMessage mail ) - throws MailSenderException - { - verify( mail ); + public void send(MailMessage mail) throws MailSenderException { + verify(mail); - try - { + try { Authenticator auth = null; - if ( getUsername() != null ) - { - auth = new Authenticator() - { - protected PasswordAuthentication getPasswordAuthentication() - { - return new PasswordAuthentication( getUsername(), getPassword() ); + if (getUsername() != null) { + auth = new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(getUsername(), getPassword()); } }; } - Session session = Session.getDefaultInstance( props, auth ); + Session session = Session.getDefaultInstance(props, auth); - session.setDebug( getLogger().isDebugEnabled() ); + session.setDebug(getLogger().isDebugEnabled()); - Message msg = new MimeMessage( session ); - InternetAddress addressFrom = new InternetAddress( mail.getFrom().getRfc2822Address() ); - msg.setFrom( addressFrom ); + Message msg = new MimeMessage(session); + InternetAddress addressFrom = new InternetAddress(mail.getFrom().getRfc2822Address()); + msg.setFrom(addressFrom); - if ( mail.getToAddresses().size() > 0 ) - { - InternetAddress[] addressTo = new InternetAddress[mail.getToAddresses().size()]; + if (mail.getToAddresses().size() > 0) { + InternetAddress[] addressTo = + new InternetAddress[mail.getToAddresses().size()]; int count = 0; - for ( Object o : mail.getToAddresses() ) - { - String address = ( (MailMessage.Address) o ).getRfc2822Address(); - addressTo[count++] = new InternetAddress( address ); + for (Object o : mail.getToAddresses()) { + String address = ((MailMessage.Address) o).getRfc2822Address(); + addressTo[count++] = new InternetAddress(address); } - msg.setRecipients( Message.RecipientType.TO, addressTo ); + msg.setRecipients(Message.RecipientType.TO, addressTo); } - if ( mail.getCcAddresses().size() > 0 ) - { - InternetAddress[] addressCc = new InternetAddress[mail.getCcAddresses().size()]; + if (mail.getCcAddresses().size() > 0) { + InternetAddress[] addressCc = + new InternetAddress[mail.getCcAddresses().size()]; int count = 0; - for ( Object o : mail.getCcAddresses() ) - { - String address = ( (MailMessage.Address) o ).getRfc2822Address(); - addressCc[count++] = new InternetAddress( address ); + for (Object o : mail.getCcAddresses()) { + String address = ((MailMessage.Address) o).getRfc2822Address(); + addressCc[count++] = new InternetAddress(address); } - msg.setRecipients( Message.RecipientType.CC, addressCc ); + msg.setRecipients(Message.RecipientType.CC, addressCc); } - if ( mail.getBccAddresses().size() > 0 ) - { - InternetAddress[] addressBcc = new InternetAddress[mail.getBccAddresses().size()]; + if (mail.getBccAddresses().size() > 0) { + InternetAddress[] addressBcc = + new InternetAddress[mail.getBccAddresses().size()]; int count = 0; - for ( Object o : mail.getBccAddresses() ) - { - String address = ( (MailMessage.Address ) o ).getRfc2822Address(); - addressBcc[count++] = new InternetAddress( address ); + for (Object o : mail.getBccAddresses()) { + String address = ((MailMessage.Address) o).getRfc2822Address(); + addressBcc[count++] = new InternetAddress(address); } - msg.setRecipients( Message.RecipientType.BCC, addressBcc ); + msg.setRecipients(Message.RecipientType.BCC, addressBcc); } // Setting the Subject and Content Type - msg.setSubject( mail.getSubject() ); - msg.setContent( mail.getContent(), mail.getContentType() == null ? "text/plain" : mail.getContentType() ); + msg.setSubject(mail.getSubject()); + msg.setContent(mail.getContent(), mail.getContentType() == null ? "text/plain" : mail.getContentType()); - if ( mail.getSendDate() != null ) - { - msg.setHeader( "Date", DateFormatUtils.getDateHeader( mail.getSendDate() ) ); - } - else - { - msg.setHeader( "Date", DateFormatUtils.getDateHeader( new Date() ) ); + if (mail.getSendDate() != null) { + msg.setHeader("Date", DateFormatUtils.getDateHeader(mail.getSendDate())); + } else { + msg.setHeader("Date", DateFormatUtils.getDateHeader(new Date())); } // Send the message - Transport.send( msg ); - } - catch ( MessagingException e ) - { - throw new MailSenderException( "Error while sending mail.", e ); + Transport.send(msg); + } catch (MessagingException e) { + throw new MailSenderException("Error while sending mail.", e); } } } diff --git a/src/main/java/org/apache/maven/plugins/changes/AbstractChangesMojo.java b/src/main/java/org/apache/maven/plugins/changes/AbstractChangesMojo.java index 19683942..4e56293e 100644 --- a/src/main/java/org/apache/maven/plugins/changes/AbstractChangesMojo.java +++ b/src/main/java/org/apache/maven/plugins/changes/AbstractChangesMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; @@ -29,15 +28,13 @@ * @version $Id$ * @since 2.9 */ -public abstract class AbstractChangesMojo - extends AbstractMojo -{ +public abstract class AbstractChangesMojo extends AbstractMojo { /** * The current project base directory. * * @since 2.1 */ - @Parameter( property = "basedir", required = true ) + @Parameter(property = "basedir", required = true) protected String basedir; /** @@ -45,7 +42,7 @@ public abstract class AbstractChangesMojo * * @since 2.3 */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) protected MavenSession mavenSession; /** @@ -54,7 +51,7 @@ public abstract class AbstractChangesMojo * * @since 2.9 */ - @Parameter( property = "changes.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter(property = "changes.runOnlyAtExecutionRoot", defaultValue = "false") protected boolean runOnlyAtExecutionRoot; /** @@ -63,18 +60,14 @@ public abstract class AbstractChangesMojo * * @return true if the current project is at the Execution Root */ - protected boolean isThisTheExecutionRoot() - { - getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() ); - getLog().debug( "Current Folder:" + basedir ); - boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir ); - if ( result ) - { - getLog().debug( "This is the execution root." ); - } - else - { - getLog().debug( "This is NOT the execution root." ); + protected boolean isThisTheExecutionRoot() { + getLog().debug("Root Folder:" + mavenSession.getExecutionRootDirectory()); + getLog().debug("Current Folder:" + basedir); + boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir); + if (result) { + getLog().debug("This is the execution root."); + } else { + getLog().debug("This is NOT the execution root."); } return result; } diff --git a/src/main/java/org/apache/maven/plugins/changes/AbstractChangesReport.java b/src/main/java/org/apache/maven/plugins/changes/AbstractChangesReport.java index 54cd9cd7..60249de4 100644 --- a/src/main/java/org/apache/maven/plugins/changes/AbstractChangesReport.java +++ b/src/main/java/org/apache/maven/plugins/changes/AbstractChangesReport.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,16 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; import org.apache.commons.io.IOUtils; import org.apache.maven.artifact.Artifact; @@ -44,30 +52,19 @@ import org.codehaus.plexus.i18n.I18N; import org.codehaus.plexus.util.ReaderFactory; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.IOException; -import java.io.Writer; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - /** * Base class with the things that should be in AbstractMavenReport anyway. Note: This file was copied from r415312 of * AbstractProjectInfoReport in maven-project-info-reports, as a work-around to MCHANGES-88. * * @author Brett Porter */ -public abstract class AbstractChangesReport - extends AbstractMavenReport -{ +public abstract class AbstractChangesReport extends AbstractMavenReport { /** * The current project base directory. * * @since 2.10 */ - @Parameter( property = "basedir", required = true ) + @Parameter(property = "basedir", required = true) protected String basedir; /** @@ -75,7 +72,7 @@ public abstract class AbstractChangesReport * from the default build lifecycle. If the goal is run indirectly as part of a site generation, the output * directory configured in the Maven Site Plugin is used instead. */ - @Parameter( defaultValue = "${project.reporting.outputDirectory}" ) + @Parameter(defaultValue = "${project.reporting.outputDirectory}") private File outputDirectory; /** @@ -85,7 +82,7 @@ public abstract class AbstractChangesReport * * @since 2.4 */ - @Parameter( property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}" ) + @Parameter(property = "outputEncoding", defaultValue = "${project.reporting.outputEncoding}") private String outputEncoding; /** @@ -94,7 +91,7 @@ public abstract class AbstractChangesReport * * @since 2.10 */ - @Parameter( property = "changes.runOnlyAtExecutionRoot", defaultValue = "false" ) + @Parameter(property = "changes.runOnlyAtExecutionRoot", defaultValue = "false") protected boolean runOnlyAtExecutionRoot; /** @@ -102,7 +99,7 @@ public abstract class AbstractChangesReport * * @since 2.10 */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) protected MavenSession mavenSession; /** @@ -114,7 +111,7 @@ public abstract class AbstractChangesReport /** * The Maven Project. */ - @Parameter( defaultValue = "${project}", readonly = true, required = true ) + @Parameter(defaultValue = "${project}", readonly = true, required = true) protected MavenProject project; /** @@ -128,80 +125,66 @@ public abstract class AbstractChangesReport @Component protected I18N i18n; - private Artifact getSkinArtifact() - throws MojoExecutionException - { + private Artifact getSkinArtifact() throws MojoExecutionException { Skin skin = Skin.getDefaultSkin(); DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); - coordinate.setGroupId( skin.getGroupId() ); - coordinate.setArtifactId( skin.getArtifactId() ); - coordinate.setVersion( skin.getVersion() ); - ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest( mavenSession.getProjectBuildingRequest() ); - pbr.setRemoteRepositories( project.getRemoteArtifactRepositories() ); - try - { - return resolver.resolveArtifact( pbr, coordinate ).getArtifact(); - } - catch ( ArtifactResolverException e ) - { - throw new MojoExecutionException( "Couldn't resolve the skin.", e ); + coordinate.setGroupId(skin.getGroupId()); + coordinate.setArtifactId(skin.getArtifactId()); + coordinate.setVersion(skin.getVersion()); + ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(mavenSession.getProjectBuildingRequest()); + pbr.setRemoteRepositories(project.getRemoteArtifactRepositories()); + try { + return resolver.resolveArtifact(pbr, coordinate).getArtifact(); + } catch (ArtifactResolverException e) { + throw new MojoExecutionException("Couldn't resolve the skin.", e); } } - public void execute() - throws MojoExecutionException - { - if ( !canGenerateReport() ) - { + public void execute() throws MojoExecutionException { + if (!canGenerateReport()) { return; } // TODO: push to a helper? Could still be improved by taking more of the site information from the site plugin Writer writer = null; - try - { + try { DecorationModel model = new DecorationModel(); - model.setBody( new Body() ); + model.setBody(new Body()); Map attributes = new HashMap<>(); - attributes.put( "outputEncoding", getOutputEncoding() ); + attributes.put("outputEncoding", getOutputEncoding()); Locale locale = Locale.getDefault(); - SiteRenderingContext siteContext = siteRenderer.createContextForSkin( getSkinArtifact(), attributes, - model, getName( locale ), locale ); - siteContext.setOutputEncoding( getOutputEncoding() ); + SiteRenderingContext siteContext = + siteRenderer.createContextForSkin(getSkinArtifact(), attributes, model, getName(locale), locale); + siteContext.setOutputEncoding(getOutputEncoding()); - RenderingContext context = new RenderingContext( outputDirectory, getOutputName() + ".html" ); + RenderingContext context = new RenderingContext(outputDirectory, getOutputName() + ".html"); - SiteRendererSink sink = new SiteRendererSink( context ); - generate( sink, null, locale ); + SiteRendererSink sink = new SiteRendererSink(context); + generate(sink, null, locale); outputDirectory.mkdirs(); - File file = new File( outputDirectory, getOutputName() + ".html" ); - writer = new OutputStreamWriter( new FileOutputStream( file ), getOutputEncoding() ); + File file = new File(outputDirectory, getOutputName() + ".html"); + writer = new OutputStreamWriter(new FileOutputStream(file), getOutputEncoding()); - siteRenderer.generateDocument( writer, sink, siteContext ); + siteRenderer.generateDocument(writer, sink, siteContext); writer.close(); writer = null; - siteRenderer.copyResources( siteContext, outputDirectory ); - } - catch ( RendererException | IOException | MavenReportException e ) - { - throw new MojoExecutionException( "An error has occurred in " + getName( Locale.ENGLISH ) - + " report generation.", e ); - } - finally - { - IOUtils.closeQuietly( writer ); + siteRenderer.copyResources(siteContext, outputDirectory); + } catch (RendererException | IOException | MavenReportException e) { + throw new MojoExecutionException( + "An error has occurred in " + getName(Locale.ENGLISH) + " report generation.", e); + } finally { + IOUtils.closeQuietly(writer); } } /** * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory() */ - protected String getOutputDirectory() - { + protected String getOutputDirectory() { return outputDirectory.getAbsolutePath(); } @@ -211,24 +194,21 @@ protected String getOutputDirectory() * @return The effective reporting output file encoding, never null. * @since 2.4 */ - protected String getOutputEncoding() - { - return ( outputEncoding != null ) ? outputEncoding : ReaderFactory.UTF_8; + protected String getOutputEncoding() { + return (outputEncoding != null) ? outputEncoding : ReaderFactory.UTF_8; } /** * @see org.apache.maven.reporting.AbstractMavenReport#getProject() */ - protected MavenProject getProject() - { + protected MavenProject getProject() { return project; } /** * @see org.apache.maven.reporting.AbstractMavenReport#getSiteRenderer() */ - protected Renderer getSiteRenderer() - { + protected Renderer getSiteRenderer() { return siteRenderer; } @@ -238,18 +218,14 @@ protected Renderer getSiteRenderer() * * @return true if the current project is at the Execution Root */ - protected boolean isThisTheExecutionRoot() - { - getLog().debug( "Root Folder:" + mavenSession.getExecutionRootDirectory() ); - getLog().debug( "Current Folder:" + basedir ); - boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase( basedir ); - if ( result ) - { - getLog().debug( "This is the execution root." ); - } - else - { - getLog().debug( "This is NOT the execution root." ); + protected boolean isThisTheExecutionRoot() { + getLog().debug("Root Folder:" + mavenSession.getExecutionRootDirectory()); + getLog().debug("Current Folder:" + basedir); + boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir); + if (result) { + getLog().debug("This is the execution root."); + } else { + getLog().debug("This is NOT the execution root."); } return result; } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesCheckMojo.java b/src/main/java/org/apache/maven/plugins/changes/ChangesCheckMojo.java index 1c60d0e4..0ec1232e 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesCheckMojo.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesCheckMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.io.File; import java.text.ParseException; @@ -38,14 +37,12 @@ * @author Dennis Lundberg * @since 2.4 */ -@Mojo( name = "changes-check", threadSafe = true ) -public class ChangesCheckMojo - extends AbstractChangesMojo -{ +@Mojo(name = "changes-check", threadSafe = true) +public class ChangesCheckMojo extends AbstractChangesMojo { /** * The format that a correct release date should have. This value will be used as a pattern to try to parse a date. */ - @Parameter( property = "changes.releaseDateFormat", defaultValue = "yyyy-MM-dd" ) + @Parameter(property = "changes.releaseDateFormat", defaultValue = "yyyy-MM-dd") private String releaseDateFormat; /** @@ -53,19 +50,19 @@ public class ChangesCheckMojo * * @since 2.10 */ - @Parameter( property = "changes.releaseDateLocale" ) + @Parameter(property = "changes.releaseDateLocale") private String releaseDateLocale; /** * Version of the artifact. */ - @Parameter( property = "changes.version", defaultValue = "${project.version}", required = true ) + @Parameter(property = "changes.version", defaultValue = "${project.version}", required = true) private String version; /** * The path of the changes.xml file that will be checked. */ - @Parameter( property = "changes.xmlPath", defaultValue = "src/changes/changes.xml" ) + @Parameter(property = "changes.xmlPath", defaultValue = "src/changes/changes.xml") private File xmlPath; /** @@ -73,7 +70,7 @@ public class ChangesCheckMojo * * @since 2.7 */ - @Parameter( property = "changes.skipSnapshots", defaultValue = "false" ) + @Parameter(property = "changes.skipSnapshots", defaultValue = "false") private boolean skipSnapshots; /** @@ -81,37 +78,24 @@ public class ChangesCheckMojo * * @throws MojoExecutionException in case of errors. */ - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { // Run only at the execution root - if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) - { - getLog().info( "Skipping the changes check in this project because it's not the Execution Root" ); - } - else - { - if ( this.version.endsWith( "-SNAPSHOT" ) && this.skipSnapshots ) - { - getLog().info( "Skipping snapshot version '" + this.version + "'." ); - } - else if ( xmlPath.exists() ) - { - ChangesXML xml = new ChangesXML( xmlPath, getLog() ); - ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); - Release release = - releaseUtils.getLatestRelease( xml.getReleaseList(), version ); - - if ( !isValidDate( release.getDateRelease(), releaseDateFormat, releaseDateLocale ) ) - { - throw new MojoExecutionException( "The file " + xmlPath.getAbsolutePath() - + " has an invalid release date." ); - + if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) { + getLog().info("Skipping the changes check in this project because it's not the Execution Root"); + } else { + if (this.version.endsWith("-SNAPSHOT") && this.skipSnapshots) { + getLog().info("Skipping snapshot version '" + this.version + "'."); + } else if (xmlPath.exists()) { + ChangesXML xml = new ChangesXML(xmlPath, getLog()); + ReleaseUtils releaseUtils = new ReleaseUtils(getLog()); + Release release = releaseUtils.getLatestRelease(xml.getReleaseList(), version); + + if (!isValidDate(release.getDateRelease(), releaseDateFormat, releaseDateLocale)) { + throw new MojoExecutionException( + "The file " + xmlPath.getAbsolutePath() + " has an invalid release date."); } - } - else - { - getLog().warn( "The file " + xmlPath.getAbsolutePath() + " does not exist." ); + } else { + getLog().warn("The file " + xmlPath.getAbsolutePath() + " does not exist."); } } } @@ -124,9 +108,8 @@ else if ( xmlPath.exists() ) * @param pattern A pattern that can be used by {@link SimpleDateFormat} * @return true if the string can be parsed as a date using the pattern, otherwise false */ - protected static boolean isValidDate( String string, String pattern ) - { - return isValidDate( string, pattern, null ); + protected static boolean isValidDate(String string, String pattern) { + return isValidDate(string, pattern, null); } /** @@ -137,55 +120,43 @@ protected static boolean isValidDate( String string, String pattern ) * @param locale A locale that can be used by {@link SimpleDateFormat} * @return true if the string can be parsed as a date using the pattern, otherwise false */ - protected static boolean isValidDate( String string, String pattern, String locale ) - { - if ( StringUtils.isEmpty( string ) ) - { + protected static boolean isValidDate(String string, String pattern, String locale) { + if (StringUtils.isEmpty(string)) { return false; } - if ( StringUtils.isEmpty( pattern ) ) - { + if (StringUtils.isEmpty(pattern)) { return false; } - try - { + try { Locale usedLocale = null; - if ( StringUtils.isEmpty( locale ) ) - { + if (StringUtils.isEmpty(locale)) { // No locale specified, use the default locale as default value // The same behavior as before the locale parameter was added usedLocale = Locale.getDefault(); - } - else - { + } else { // Try to find the specified locale on this system Locale[] locales = Locale.getAvailableLocales(); - for ( Locale value : locales ) - { - if ( value.toString().equals( locale ) ) - { + for (Locale value : locales) { + if (value.toString().equals(locale)) { usedLocale = value; break; } } - if ( usedLocale == null ) - { + if (usedLocale == null) { // The use specified locale was not found on this system, // use the default locale as default value usedLocale = Locale.getDefault(); } } - SimpleDateFormat df = new SimpleDateFormat( pattern, usedLocale ); - df.parse( string ); + SimpleDateFormat df = new SimpleDateFormat(pattern, usedLocale); + df.parse(string); return true; - } - catch ( ParseException e ) - { + } catch (ParseException e) { return false; } } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesMojo.java b/src/main/java/org/apache/maven/plugins/changes/ChangesMojo.java index 56fa1360..58307fdc 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesMojo.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.io.File; import java.io.FileWriter; @@ -54,17 +53,15 @@ * @author Johnny R. Ruiz III * @version $Id$ */ -@Mojo( name = "changes-report", threadSafe = true ) -public class ChangesMojo - extends AbstractChangesReport -{ +@Mojo(name = "changes-report", threadSafe = true) +public class ChangesMojo extends AbstractChangesReport { /** * A flag whether the report should also include changes from child modules. If set to false, only the * changes from current project will be written to the report. * * @since 2.5 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean aggregated; /** @@ -73,7 +70,7 @@ public class ChangesMojo * * @since 2.1 */ - @Parameter( property = "changes.addActionDate", defaultValue = "false" ) + @Parameter(property = "changes.addActionDate", defaultValue = "false") private boolean addActionDate; /** @@ -98,7 +95,7 @@ public class ChangesMojo * * @since 2.2 */ - @Parameter( defaultValue = "${project.build.directory}/changes", required = true, readonly = true ) + @Parameter(defaultValue = "${project.build.directory}/changes", required = true, readonly = true) private File filteredOutputDirectory; /** @@ -106,7 +103,7 @@ public class ChangesMojo * * @since 2.2 */ - @Parameter( defaultValue = "false" ) + @Parameter(defaultValue = "false") private boolean filteringChanges; /** @@ -122,7 +119,7 @@ public class ChangesMojo * @since 2.0-beta-2 * @deprecated As of 2.1 use issueLinkTemplatePerSystem: this one will be with system default */ - @Parameter( property = "changes.issueLinkTemplate" ) + @Parameter(property = "changes.issueLinkTemplate") private String issueLinkTemplate; /** @@ -159,7 +156,7 @@ public class ChangesMojo * @see java.text.SimpleDateFormat * @since 2.2 */ - @Parameter( defaultValue = "yyyy-MM-dd" ) + @Parameter(defaultValue = "yyyy-MM-dd") private String publishDateFormat; /** @@ -168,19 +165,19 @@ public class ChangesMojo * @see java.util.Locale * @since 2.2 */ - @Parameter( defaultValue = "en" ) + @Parameter(defaultValue = "en") private String publishDateLocale; /** * @since 2.2 */ - @Parameter( defaultValue = "${session}", readonly = true, required = true ) + @Parameter(defaultValue = "${session}", readonly = true, required = true) protected MavenSession session; /** * @since 2.4 */ - @Parameter( defaultValue = "${project.issueManagement.system}", readonly = true ) + @Parameter(defaultValue = "${project.issueManagement.system}", readonly = true) private String system; /** @@ -189,12 +186,12 @@ public class ChangesMojo * * @since 2.4 */ - @Parameter( defaultValue = "team.html" ) + @Parameter(defaultValue = "team.html") private String team; /** */ - @Parameter( defaultValue = "${project.issueManagement.url}", readonly = true ) + @Parameter(defaultValue = "${project.issueManagement.url}", readonly = true) private String url; /** @@ -215,10 +212,10 @@ public class ChangesMojo /** * The path of the changes.xml file that will be converted into an HTML report. */ - @Parameter( property = "changes.xmlPath", defaultValue = "src/changes/changes.xml" ) + @Parameter(property = "changes.xmlPath", defaultValue = "src/changes/changes.xml") private File xmlPath; - private ReleaseUtils releaseUtils = new ReleaseUtils( getLog() ); + private ReleaseUtils releaseUtils = new ReleaseUtils(getLog()); private CaseInsensitiveMap caseInsensitiveIssueLinkTemplatePerSystem; @@ -226,154 +223,136 @@ public class ChangesMojo /* Public methods */ /* --------------------------------------------------------------------- */ - public boolean canGenerateReport() - { + public boolean canGenerateReport() { // Run only at the execution root - if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) - { - getLog().info( "Skipping the Changes Report in this project because it's not the Execution Root" ); + if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) { + getLog().info("Skipping the Changes Report in this project because it's not the Execution Root"); return false; } return xmlPath.isFile(); } - public void executeReport( Locale locale ) - throws MavenReportException - { - failIfUsingDeprecatedParameter( escapeHTML, "escapeHTML", - "Using markup inside CDATA sections does not work for all output formats!" ); - failIfUsingDeprecatedParameter( issueLinkTemplate, "issueLinkTemplate", - "You must use 'issueLinkTemplatePerSystem' for the system '" - + ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY + "' instead." ); + public void executeReport(Locale locale) throws MavenReportException { + failIfUsingDeprecatedParameter( + escapeHTML, "escapeHTML", "Using markup inside CDATA sections does not work for all output formats!"); + failIfUsingDeprecatedParameter( + issueLinkTemplate, + "issueLinkTemplate", + "You must use 'issueLinkTemplatePerSystem' for the system '" + + ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY + "' instead."); Date now = new Date(); - SimpleDateFormat simpleDateFormat = new SimpleDateFormat( publishDateFormat, new Locale( publishDateLocale ) ); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(publishDateFormat, new Locale(publishDateLocale)); Properties additionalProperties = new Properties(); - additionalProperties.put( "publishDate", simpleDateFormat.format( now ) ); + additionalProperties.put("publishDate", simpleDateFormat.format(now)); - ChangesXML changesXml = getChangesFromFile( xmlPath, project, additionalProperties ); - if ( changesXml == null ) - { + ChangesXML changesXml = getChangesFromFile(xmlPath, project, additionalProperties); + if (changesXml == null) { return; } - if ( aggregated ) - { + if (aggregated) { final String basePath = project.getBasedir().getAbsolutePath(); final String absolutePath = xmlPath.getAbsolutePath(); - if ( !absolutePath.startsWith( basePath ) ) - { - getLog().warn( "xmlPath should be within the project dir for aggregated changes report." ); + if (!absolutePath.startsWith(basePath)) { + getLog().warn("xmlPath should be within the project dir for aggregated changes report."); return; } - final String relativePath = absolutePath.substring( basePath.length() ); + final String relativePath = absolutePath.substring(basePath.length()); List releaseList = changesXml.getReleaseList(); - for ( Object o : project.getCollectedProjects() ) - { + for (Object o : project.getCollectedProjects()) { final MavenProject childProject = (MavenProject) o; - final File changesFile = new File( childProject.getBasedir(), relativePath ); - final ChangesXML childXml = getChangesFromFile( changesFile, childProject, additionalProperties ); - if ( childXml != null ) - { + final File changesFile = new File(childProject.getBasedir(), relativePath); + final ChangesXML childXml = getChangesFromFile(changesFile, childProject, additionalProperties); + if (childXml != null) { releaseList = - releaseUtils.mergeReleases( releaseList, childProject.getName(), childXml.getReleaseList() ); + releaseUtils.mergeReleases(releaseList, childProject.getName(), childXml.getReleaseList()); } } - changesXml.setReleaseList( releaseList ); + changesXml.setReleaseList(releaseList); } - ChangesReportGenerator report = new ChangesReportGenerator( changesXml.getReleaseList() ); + ChangesReportGenerator report = new ChangesReportGenerator(changesXml.getReleaseList()); - report.setAuthor( changesXml.getAuthor() ); - report.setTitle( changesXml.getTitle() ); + report.setAuthor(changesXml.getAuthor()); + report.setTitle(changesXml.getTitle()); - report.setEscapeHTML( true ); + report.setEscapeHTML(true); // Create a case insensitive version of issueLinkTemplatePerSystem // We need something case insensitive to maintain backward compatibility - if ( issueLinkTemplatePerSystem == null ) - { + if (issueLinkTemplatePerSystem == null) { caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap(); - } - else - { - caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap( issueLinkTemplatePerSystem ); + } else { + caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap(issueLinkTemplatePerSystem); } // Set good default values for issue management systems here - addIssueLinkTemplate( ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY, "%URL%/ViewIssue.jspa?key=%ISSUE%" ); - addIssueLinkTemplate( "Bitbucket", "%URL%/issue/%ISSUE%" ); - addIssueLinkTemplate( "Bugzilla", "%URL%/show_bug.cgi?id=%ISSUE%" ); - addIssueLinkTemplate( "GitHub", "%URL%/%ISSUE%" ); - addIssueLinkTemplate( "GoogleCode", "%URL%/detail?id=%ISSUE%" ); - addIssueLinkTemplate( "JIRA", "%URL%/%ISSUE%" ); - addIssueLinkTemplate( "Mantis", "%URL%/view.php?id=%ISSUE%" ); - addIssueLinkTemplate( "MKS", "%URL%/viewissue?selection=%ISSUE%" ); - addIssueLinkTemplate( "Redmine", "%URL%/issues/show/%ISSUE%" ); - addIssueLinkTemplate( "Scarab", "%URL%/issues/id/%ISSUE%" ); - addIssueLinkTemplate( "SourceForge", "http://sourceforge.net/support/tracker.php?aid=%ISSUE%" ); - addIssueLinkTemplate( "SourceForge2", "%URL%/%ISSUE%" ); - addIssueLinkTemplate( "Trac", "%URL%/ticket/%ISSUE%" ); - addIssueLinkTemplate( "Trackplus", "%URL%/printItem.action?key=%ISSUE%" ); - addIssueLinkTemplate( "Tuleap", "%URL%/?aid=%ISSUE%" ); - addIssueLinkTemplate( "YouTrack", "%URL%/issue/%ISSUE%" ); + addIssueLinkTemplate(ChangesReportGenerator.DEFAULT_ISSUE_SYSTEM_KEY, "%URL%/ViewIssue.jspa?key=%ISSUE%"); + addIssueLinkTemplate("Bitbucket", "%URL%/issue/%ISSUE%"); + addIssueLinkTemplate("Bugzilla", "%URL%/show_bug.cgi?id=%ISSUE%"); + addIssueLinkTemplate("GitHub", "%URL%/%ISSUE%"); + addIssueLinkTemplate("GoogleCode", "%URL%/detail?id=%ISSUE%"); + addIssueLinkTemplate("JIRA", "%URL%/%ISSUE%"); + addIssueLinkTemplate("Mantis", "%URL%/view.php?id=%ISSUE%"); + addIssueLinkTemplate("MKS", "%URL%/viewissue?selection=%ISSUE%"); + addIssueLinkTemplate("Redmine", "%URL%/issues/show/%ISSUE%"); + addIssueLinkTemplate("Scarab", "%URL%/issues/id/%ISSUE%"); + addIssueLinkTemplate("SourceForge", "http://sourceforge.net/support/tracker.php?aid=%ISSUE%"); + addIssueLinkTemplate("SourceForge2", "%URL%/%ISSUE%"); + addIssueLinkTemplate("Trac", "%URL%/ticket/%ISSUE%"); + addIssueLinkTemplate("Trackplus", "%URL%/printItem.action?key=%ISSUE%"); + addIssueLinkTemplate("Tuleap", "%URL%/?aid=%ISSUE%"); + addIssueLinkTemplate("YouTrack", "%URL%/issue/%ISSUE%"); // @todo Add more issue management systems here // Remember to also add documentation in usage.apt.vm // Show the current issueLinkTemplatePerSystem configuration - logIssueLinkTemplatePerSystem( caseInsensitiveIssueLinkTemplatePerSystem ); + logIssueLinkTemplatePerSystem(caseInsensitiveIssueLinkTemplatePerSystem); - report.setIssueLinksPerSystem( caseInsensitiveIssueLinkTemplatePerSystem ); + report.setIssueLinksPerSystem(caseInsensitiveIssueLinkTemplatePerSystem); - report.setSystem( system ); + report.setSystem(system); - report.setTeam( team ); + report.setTeam(team); - report.setUrl( url ); + report.setUrl(url); - report.setAddActionDate( addActionDate ); + report.setAddActionDate(addActionDate); - if ( url == null || url.isEmpty() ) - { - getLog().warn( "No issue management URL defined in POM. Links to your issues will not work correctly." ); + if (url == null || url.isEmpty()) { + getLog().warn("No issue management URL defined in POM. Links to your issues will not work correctly."); } boolean feedGenerated = false; - if ( feedType != null && !feedType.isEmpty() ) - { - feedGenerated = generateFeed( changesXml, locale ); + if (feedType != null && !feedType.isEmpty()) { + feedGenerated = generateFeed(changesXml, locale); } - report.setLinkToFeed( feedGenerated ); + report.setLinkToFeed(feedGenerated); - report.doGenerateReport( getBundle( locale ), getSink() ); + report.doGenerateReport(getBundle(locale), getSink()); // Copy the images copyStaticResources(); } - private void failIfUsingDeprecatedParameter( Object value, String name, String message ) - throws MavenReportException - { - if ( value != null ) - { - throw new MavenReportException( "You are using the old parameter '" + name + "'. " + message ); + private void failIfUsingDeprecatedParameter(Object value, String name, String message) throws MavenReportException { + if (value != null) { + throw new MavenReportException("You are using the old parameter '" + name + "'. " + message); } } - public String getDescription( Locale locale ) - { - return getBundle( locale ).getString( "report.issues.description" ); + public String getDescription(Locale locale) { + return getBundle(locale).getString("report.issues.description"); } - public String getName( Locale locale ) - { - return getBundle( locale ).getString( "report.issues.name" ); + public String getName(Locale locale) { + return getBundle(locale).getString("report.issues.name"); } - public String getOutputName() - { + public String getOutputName() { return "changes-report"; } @@ -391,44 +370,43 @@ public String getOutputName() * @return parsed ChangesXML instance or null if file doesn't exist * @throws MavenReportException if any errors occurs while parsing */ - private ChangesXML getChangesFromFile( File changesXml, MavenProject project, Properties additionalProperties ) - throws MavenReportException - { - if ( !changesXml.exists() ) - { - getLog().warn( "changes.xml file " + changesXml.getAbsolutePath() + " does not exist." ); + private ChangesXML getChangesFromFile(File changesXml, MavenProject project, Properties additionalProperties) + throws MavenReportException { + if (!changesXml.exists()) { + getLog().warn("changes.xml file " + changesXml.getAbsolutePath() + " does not exist."); return null; } - if ( filteringChanges ) - { - if ( !filteredOutputDirectory.exists() ) - { + if (filteringChanges) { + if (!filteredOutputDirectory.exists()) { filteredOutputDirectory.mkdirs(); } - try - { + try { // so we get encoding from the file itself - try ( XmlStreamReader xmlStreamReader = new XmlStreamReader( changesXml ) ) - { + try (XmlStreamReader xmlStreamReader = new XmlStreamReader(changesXml)) { String encoding = xmlStreamReader.getEncoding(); - File resultFile = new File( filteredOutputDirectory, - project.getGroupId() + "." + project.getArtifactId() + "-changes.xml" ); - - final MavenFileFilterRequest mavenFileFilterRequest = - new MavenFileFilterRequest( changesXml, resultFile, true, project, - Collections.emptyList(), false, encoding, session, additionalProperties ); - mavenFileFilter.copyFile( mavenFileFilterRequest ); + File resultFile = new File( + filteredOutputDirectory, + project.getGroupId() + "." + project.getArtifactId() + "-changes.xml"); + + final MavenFileFilterRequest mavenFileFilterRequest = new MavenFileFilterRequest( + changesXml, + resultFile, + true, + project, + Collections.emptyList(), + false, + encoding, + session, + additionalProperties); + mavenFileFilter.copyFile(mavenFileFilterRequest); changesXml = resultFile; } + } catch (IOException | MavenFilteringException e) { + throw new MavenReportException("Exception during filtering changes file : " + e.getMessage(), e); } - catch ( IOException | MavenFilteringException e ) - { - throw new MavenReportException( "Exception during filtering changes file : " + e.getMessage(), e ); - } - } - return new ChangesXML( changesXml, getLog() ); + return new ChangesXML(changesXml, getLog()); } /** @@ -439,105 +417,85 @@ private ChangesXML getChangesFromFile( File changesXml, MavenProject project, Pr * @param issueLinkTemplate The issue link template to use * @since 2.4 */ - private void addIssueLinkTemplate( String system, String issueLinkTemplate ) - { - if ( caseInsensitiveIssueLinkTemplatePerSystem == null ) - { + private void addIssueLinkTemplate(String system, String issueLinkTemplate) { + if (caseInsensitiveIssueLinkTemplatePerSystem == null) { caseInsensitiveIssueLinkTemplatePerSystem = new CaseInsensitiveMap(); } - if ( !caseInsensitiveIssueLinkTemplatePerSystem.containsKey( system ) ) - { - caseInsensitiveIssueLinkTemplatePerSystem.put( system, issueLinkTemplate ); + if (!caseInsensitiveIssueLinkTemplatePerSystem.containsKey(system)) { + caseInsensitiveIssueLinkTemplatePerSystem.put(system, issueLinkTemplate); } } - private void copyStaticResources() - throws MavenReportException - { + private void copyStaticResources() throws MavenReportException { final String pluginResourcesBase = "org/apache/maven/plugins/changes"; - String[] resourceNames = { "images/add.gif", "images/fix.gif", "images/icon_help_sml.gif", "images/remove.gif", - "images/rss.png", "images/update.gif" }; - try - { - getLog().debug( "Copying static resources." ); - for ( String resourceName : resourceNames ) - { - URL url = this.getClass().getClassLoader().getResource( pluginResourcesBase + "/" + resourceName ); - FileUtils.copyURLToFile( url, new File( getReportOutputDirectory(), resourceName ) ); + String[] resourceNames = { + "images/add.gif", + "images/fix.gif", + "images/icon_help_sml.gif", + "images/remove.gif", + "images/rss.png", + "images/update.gif" + }; + try { + getLog().debug("Copying static resources."); + for (String resourceName : resourceNames) { + URL url = this.getClass().getClassLoader().getResource(pluginResourcesBase + "/" + resourceName); + FileUtils.copyURLToFile(url, new File(getReportOutputDirectory(), resourceName)); } - } - catch ( IOException e ) - { - throw new MavenReportException( "Unable to copy static resources." ); + } catch (IOException e) { + throw new MavenReportException("Unable to copy static resources."); } } - private ResourceBundle getBundle( Locale locale ) - { - return ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() ); + private ResourceBundle getBundle(Locale locale) { + return ResourceBundle.getBundle( + "changes-report", locale, this.getClass().getClassLoader()); } - protected String getTeam() - { + protected String getTeam() { return team; } - private void logIssueLinkTemplatePerSystem( Map issueLinkTemplatePerSystem ) - { - if ( getLog().isDebugEnabled() ) - { - if ( issueLinkTemplatePerSystem == null ) - { - getLog().debug( "No issueLinkTemplatePerSystem configuration was found" ); - } - else - { - for ( Entry entry : issueLinkTemplatePerSystem.entrySet() ) - { - getLog().debug( "issueLinkTemplatePerSystem[" + entry.getKey() + "] = " + entry.getValue() ); + private void logIssueLinkTemplatePerSystem(Map issueLinkTemplatePerSystem) { + if (getLog().isDebugEnabled()) { + if (issueLinkTemplatePerSystem == null) { + getLog().debug("No issueLinkTemplatePerSystem configuration was found"); + } else { + for (Entry entry : issueLinkTemplatePerSystem.entrySet()) { + getLog().debug("issueLinkTemplatePerSystem[" + entry.getKey() + "] = " + entry.getValue()); } } } } - private boolean generateFeed( final ChangesXML changesXml, final Locale locale ) - { - getLog().debug( "Generating " + feedType + " feed." ); + private boolean generateFeed(final ChangesXML changesXml, final Locale locale) { + getLog().debug("Generating " + feedType + " feed."); boolean success = true; - final FeedGenerator feed = new FeedGenerator( locale ); - feed.setLink( project.getUrl() + "/changes-report.html" ); // TODO: better way? - feed.setTitle( project.getName() + ": " + changesXml.getTitle() ); - feed.setAuthor( changesXml.getAuthor() ); - feed.setDateFormat( new SimpleDateFormat( publishDateFormat, new Locale( publishDateLocale ) ) ); + final FeedGenerator feed = new FeedGenerator(locale); + feed.setLink(project.getUrl() + "/changes-report.html"); // TODO: better way? + feed.setTitle(project.getName() + ": " + changesXml.getTitle()); + feed.setAuthor(changesXml.getAuthor()); + feed.setDateFormat(new SimpleDateFormat(publishDateFormat, new Locale(publishDateLocale))); Writer writer = null; - try - { - writer = new FileWriter( new File( getReportOutputDirectory(), "changes.rss" ) ); - feed.export( changesXml.getReleaseList(), feedType, writer ); - } - catch ( IOException ex ) - { + try { + writer = new FileWriter(new File(getReportOutputDirectory(), "changes.rss")); + feed.export(changesXml.getReleaseList(), feedType, writer); + } catch (IOException ex) { success = false; - getLog().warn( "Failed to create rss feed: " + ex.getMessage() ); - getLog().debug( ex ); - } - finally - { - try - { - if ( writer != null ) - { + getLog().warn("Failed to create rss feed: " + ex.getMessage()); + getLog().debug(ex); + } finally { + try { + if (writer != null) { writer.close(); } - } - catch ( IOException ex ) - { - getLog().warn( "Failed to close writer: " + ex.getMessage() ); - getLog().debug( ex ); + } catch (IOException ex) { + getLog().warn("Failed to close writer: " + ex.getMessage()); + getLog().debug(ex); } } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesReportGenerator.java b/src/main/java/org/apache/maven/plugins/changes/ChangesReportGenerator.java index d962f734..a1ff1dfb 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesReportGenerator.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesReportGenerator.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.util.HashMap; import java.util.Iterator; @@ -27,7 +26,6 @@ import java.util.ResourceBundle; import org.apache.commons.lang.StringUtils; - import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventAttributes; import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; @@ -44,9 +42,7 @@ * * @version $Id$ */ -public class ChangesReportGenerator - extends AbstractIssuesReportGenerator -{ +public class ChangesReportGenerator extends AbstractIssuesReportGenerator { /** * The token in {@link #issueLinksPerSystem} denoting the base URL for the issue management. @@ -89,88 +85,71 @@ public class ChangesReportGenerator */ private List releaseList; - public ChangesReportGenerator() - { + public ChangesReportGenerator() { issueLinksPerSystem = new HashMap<>(); } - public ChangesReportGenerator( List releaseList ) - { + public ChangesReportGenerator(List releaseList) { this(); this.releaseList = releaseList; } - public boolean isEscapeHTML() - { + public boolean isEscapeHTML() { return escapeHTML; } - public void setEscapeHTML( boolean escapeHTML ) - { + public void setEscapeHTML(boolean escapeHTML) { this.escapeHTML = escapeHTML; } - public String getSystem() - { + public String getSystem() { return system; } - public void setSystem( String system ) - { + public void setSystem(String system) { this.system = system; } - public void setTeam( final String team ) - { + public void setTeam(final String team) { this.team = team; } - public String getTeam() - { + public String getTeam() { return team; } - public void setUrl( String url ) - { + public void setUrl(String url) { this.url = url; } - public String getUrl() - { + public String getUrl() { return url; } - public Map getIssueLinksPerSystem() - { + public Map getIssueLinksPerSystem() { return issueLinksPerSystem; } - public void setIssueLinksPerSystem( Map issueLinksPerSystem ) - { - if ( this.issueLinksPerSystem != null && issueLinksPerSystem == null ) - { + public void setIssueLinksPerSystem(Map issueLinksPerSystem) { + if (this.issueLinksPerSystem != null && issueLinksPerSystem == null) { return; } this.issueLinksPerSystem = issueLinksPerSystem; } - public boolean isAddActionDate() - { + public boolean isAddActionDate() { return addActionDate; } - public void setAddActionDate( boolean addActionDate ) - { + public void setAddActionDate(boolean addActionDate) { this.addActionDate = addActionDate; } - public boolean isLinkToFeed() - { + public boolean isLinkToFeed() { return linkToFeed; } - public void setLinkToFeed( boolean generateLinkTofeed ) - { + public void setLinkToFeed(boolean generateLinkTofeed) { this.linkToFeed = generateLinkTofeed; } @@ -180,46 +159,40 @@ public void setLinkToFeed( boolean generateLinkTofeed ) * @param system The issue management system * @return true if issue links can be generated, false otherwise. */ - public boolean canGenerateIssueLinks( String system ) - { - if ( !this.issueLinksPerSystem.containsKey( system ) ) - { + public boolean canGenerateIssueLinks(String system) { + if (!this.issueLinksPerSystem.containsKey(system)) { return false; } - String issueLink = this.issueLinksPerSystem.get( system ); + String issueLink = this.issueLinksPerSystem.get(system); // If the issue link entry is blank then no links are possible - if ( StringUtils.isBlank( issueLink ) ) - { + if (StringUtils.isBlank(issueLink)) { return false; } // If the %URL% token is used then the issue management system URL must be set. - if ( issueLink.contains( URL_TOKEN ) && StringUtils.isBlank( getUrl() ) ) - { + if (issueLink.contains(URL_TOKEN) && StringUtils.isBlank(getUrl())) { return false; } return true; } - public void doGenerateEmptyReport( ResourceBundle bundle, Sink sink, String message ) - { - sinkBeginReport( sink, bundle ); + public void doGenerateEmptyReport(ResourceBundle bundle, Sink sink, String message) { + sinkBeginReport(sink, bundle); - sink.text( message ); + sink.text(message); - sinkEndReport( sink ); + sinkEndReport(sink); } - public void doGenerateReport( ResourceBundle bundle, Sink sink ) - { - sinkBeginReport( sink, bundle ); + public void doGenerateReport(ResourceBundle bundle, Sink sink) { + sinkBeginReport(sink, bundle); - constructReleaseHistory( sink, bundle, releaseList ); + constructReleaseHistory(sink, bundle, releaseList); - constructReleases( sink, bundle, releaseList ); + constructReleases(sink, bundle, releaseList); - sinkEndReport( sink ); + sinkEndReport(sink); } /** @@ -229,76 +202,61 @@ public void doGenerateReport( ResourceBundle bundle, Sink sink ) * @param bundle Resource bundle * @param action Action to generate content for */ - private void constructAction( Sink sink, ResourceBundle bundle, Action action ) - { + private void constructAction(Sink sink, ResourceBundle bundle, Action action) { sink.tableRow(); - sinkShowTypeIcon( sink, action.getType() ); + sinkShowTypeIcon(sink, action.getType()); sink.tableCell(); String actionDescription = action.getAction(); - if ( escapeHTML ) - { - sink.text( actionDescription ); - } - else - { - sink.rawText( actionDescription ); + if (escapeHTML) { + sink.text(actionDescription); + } else { + sink.rawText(actionDescription); } // no null check needed classes from modello return a new ArrayList - if ( StringUtils.isNotEmpty( action.getIssue() ) || ( !action.getFixedIssues().isEmpty() ) ) - { - if ( StringUtils.isNotBlank( actionDescription ) && !actionDescription.endsWith( "." ) ) - { - sink.text( "." ); + if (StringUtils.isNotEmpty(action.getIssue()) + || (!action.getFixedIssues().isEmpty())) { + if (StringUtils.isNotBlank(actionDescription) && !actionDescription.endsWith(".")) { + sink.text("."); } - sink.text( " " + bundle.getString( "report.changes.text.fixes" ) + " " ); + sink.text(" " + bundle.getString("report.changes.text.fixes") + " "); // Try to get the issue management system specified in the changes.xml file String system = action.getSystem(); // Try to get the issue management system configured in the POM - if ( StringUtils.isEmpty( system ) ) - { + if (StringUtils.isEmpty(system)) { system = this.system; } // Use the default issue management system - if ( StringUtils.isEmpty( system ) ) - { + if (StringUtils.isEmpty(system)) { system = DEFAULT_ISSUE_SYSTEM_KEY; } - if ( !canGenerateIssueLinks( system ) ) - { - constructIssueText( action.getIssue(), sink, action.getFixedIssues() ); - } - else - { - constructIssueLink( action.getIssue(), system, sink, action.getFixedIssues() ); + if (!canGenerateIssueLinks(system)) { + constructIssueText(action.getIssue(), sink, action.getFixedIssues()); + } else { + constructIssueLink(action.getIssue(), system, sink, action.getFixedIssues()); } - sink.text( "." ); + sink.text("."); } - if ( StringUtils.isNotEmpty( action.getDueTo() ) || ( !action.getDueTos().isEmpty() ) ) - { - constructDueTo( sink, action, bundle, action.getDueTos() ); + if (StringUtils.isNotEmpty(action.getDueTo()) || (!action.getDueTos().isEmpty())) { + constructDueTo(sink, action, bundle, action.getDueTos()); } sink.tableCell_(); - if ( NO_TEAM.equals( team ) ) - { - sinkCell( sink, action.getDev() ); - } - else - { - sinkCellLink( sink, action.getDev(), team + "#" + action.getDev() ); + if (NO_TEAM.equals(team)) { + sinkCell(sink, action.getDev()); + } else { + sinkCellLink(sink, action.getDev(), team + "#" + action.getDev()); } - if ( this.isAddActionDate() ) - { - sinkCell( sink, action.getDate() ); + if (this.isAddActionDate()) { + sinkCell(sink, action.getDate()); } sink.tableRow_(); @@ -312,51 +270,42 @@ private void constructAction( Sink sink, ResourceBundle bundle, Action action ) * @param bundle A resource bundle for i18n * @param dueTos Other people that helped with an action */ - private void constructDueTo( Sink sink, Action action, ResourceBundle bundle, List dueTos ) - { + private void constructDueTo(Sink sink, Action action, ResourceBundle bundle, List dueTos) { // Create a Map with key : dueTo name, value : dueTo email Map namesEmailMap = new LinkedHashMap<>(); // Only add the dueTo specified as attributes, if it has either a dueTo or a dueToEmail - if ( StringUtils.isNotEmpty( action.getDueTo() ) || StringUtils.isNotEmpty( action.getDueToEmail() ) ) - { - namesEmailMap.put( action.getDueTo(), action.getDueToEmail() ); + if (StringUtils.isNotEmpty(action.getDueTo()) || StringUtils.isNotEmpty(action.getDueToEmail())) { + namesEmailMap.put(action.getDueTo(), action.getDueToEmail()); } - for ( DueTo dueTo : dueTos ) - { - namesEmailMap.put( dueTo.getName(), dueTo.getEmail() ); + for (DueTo dueTo : dueTos) { + namesEmailMap.put(dueTo.getName(), dueTo.getEmail()); } - if ( namesEmailMap.isEmpty() ) - { + if (namesEmailMap.isEmpty()) { return; } - sink.text( " " + bundle.getString( "report.changes.text.thanx" ) + " " ); + sink.text(" " + bundle.getString("report.changes.text.thanx") + " "); int i = 0; - for ( String currentDueTo : namesEmailMap.keySet() ) - { - String currentDueToEmail = namesEmailMap.get( currentDueTo ); + for (String currentDueTo : namesEmailMap.keySet()) { + String currentDueToEmail = namesEmailMap.get(currentDueTo); i++; - if ( StringUtils.isNotEmpty( currentDueToEmail ) ) - { - sinkLink( sink, currentDueTo, "mailto:" + currentDueToEmail ); - } - else if ( StringUtils.isNotEmpty( currentDueTo ) ) - { - sink.text( currentDueTo ); + if (StringUtils.isNotEmpty(currentDueToEmail)) { + sinkLink(sink, currentDueTo, "mailto:" + currentDueToEmail); + } else if (StringUtils.isNotEmpty(currentDueTo)) { + sink.text(currentDueTo); } - if ( i < namesEmailMap.size() ) - { - sink.text( ", " ); + if (i < namesEmailMap.size()) { + sink.text(", "); } } - sink.text( "." ); + sink.text("."); } /** @@ -367,38 +316,32 @@ else if ( StringUtils.isNotEmpty( currentDueTo ) ) * @param sink The sink * @param fixes The List of issues specified as fixes elements */ - private void constructIssueLink( String issue, String system, Sink sink, List fixes ) - { - if ( StringUtils.isNotEmpty( issue ) ) - { - sink.link( parseIssueLink( issue, system ) ); + private void constructIssueLink(String issue, String system, Sink sink, List fixes) { + if (StringUtils.isNotEmpty(issue)) { + sink.link(parseIssueLink(issue, system)); - sink.text( issue ); + sink.text(issue); sink.link_(); - if ( !fixes.isEmpty() ) - { - sink.text( ", " ); + if (!fixes.isEmpty()) { + sink.text(", "); } } - for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) - { + for (Iterator iterator = fixes.iterator(); iterator.hasNext(); ) { FixedIssue fixedIssue = iterator.next(); String currentIssueId = fixedIssue.getIssue(); - if ( StringUtils.isNotEmpty( currentIssueId ) ) - { - sink.link( parseIssueLink( currentIssueId, system ) ); + if (StringUtils.isNotEmpty(currentIssueId)) { + sink.link(parseIssueLink(currentIssueId, system)); - sink.text( currentIssueId ); + sink.text(currentIssueId); sink.link_(); } - if ( iterator.hasNext() ) - { - sink.text( ", " ); + if (iterator.hasNext()) { + sink.text(", "); } } } @@ -410,64 +353,56 @@ private void constructIssueLink( String issue, String system, Sink sink, List fixes ) - { - if ( StringUtils.isNotEmpty( issue ) ) - { - sink.text( issue ); - - if ( !fixes.isEmpty() ) - { - sink.text( ", " ); + private void constructIssueText(String issue, Sink sink, List fixes) { + if (StringUtils.isNotEmpty(issue)) { + sink.text(issue); + + if (!fixes.isEmpty()) { + sink.text(", "); } } - for ( Iterator iterator = fixes.iterator(); iterator.hasNext(); ) - { + for (Iterator iterator = fixes.iterator(); iterator.hasNext(); ) { FixedIssue fixedIssue = iterator.next(); String currentIssueId = fixedIssue.getIssue(); - if ( StringUtils.isNotEmpty( currentIssueId ) ) - { - sink.text( currentIssueId ); + if (StringUtils.isNotEmpty(currentIssueId)) { + sink.text(currentIssueId); } - if ( iterator.hasNext() ) - { - sink.text( ", " ); + if (iterator.hasNext()) { + sink.text(", "); } } } - private void constructReleaseHistory( Sink sink, ResourceBundle bundle, List releaseList ) - { + private void constructReleaseHistory(Sink sink, ResourceBundle bundle, List releaseList) { sink.section2(); sink.sectionTitle2(); - sink.text( bundle.getString( "report.changes.label.releasehistory" ) ); + sink.text(bundle.getString("report.changes.label.releasehistory")); sink.sectionTitle2_(); sink.table(); sink.tableRow(); - sinkHeader( sink, bundle.getString( "report.issues.label.fixVersion" ) ); + sinkHeader(sink, bundle.getString("report.issues.label.fixVersion")); - sinkHeader( sink, bundle.getString( "report.changes.label.releaseDate" ) ); + sinkHeader(sink, bundle.getString("report.changes.label.releaseDate")); - sinkHeader( sink, bundle.getString( "report.changes.label.releaseDescription" ) ); + sinkHeader(sink, bundle.getString("report.changes.label.releaseDescription")); sink.tableRow_(); - for ( Release release : releaseList ) - { + for (Release release : releaseList) { sink.tableRow(); - sinkCellLink( sink, release.getVersion(), "#" + HtmlTools.encodeId( release.getVersion() ) ); + sinkCellLink(sink, release.getVersion(), "#" + HtmlTools.encodeId(release.getVersion())); - sinkCell( sink, release.getDateRelease() ); + sinkCell(sink, release.getDateRelease()); - sinkCell( sink, release.getDescription() ); + sinkCell(sink, release.getDescription()); sink.tableRow_(); } @@ -475,13 +410,12 @@ private void constructReleaseHistory( Sink sink, ResourceBundle bundle, List releaseList ) - { - for ( Release release : releaseList ) - { - constructRelease( sink, bundle, release ); + private void constructReleases(Sink sink, ResourceBundle bundle, List releaseList) { + for (Release release : releaseList) { + constructRelease(sink, bundle, release); } } @@ -511,47 +443,40 @@ private void constructReleases( Sink sink, ResourceBundle bundle, List * @param bundle Resource bundle * @param release Release to create document section for */ - private void constructRelease( Sink sink, ResourceBundle bundle, Release release ) - { + private void constructRelease(Sink sink, ResourceBundle bundle, Release release) { sink.section2(); - final String date = ( release.getDateRelease() == null ) ? "" : " \u2013 " + release.getDateRelease(); + final String date = (release.getDateRelease() == null) ? "" : " \u2013 " + release.getDateRelease(); SinkEventAttributes attrs = new SinkEventAttributeSet(); - attrs.addAttribute( SinkEventAttributes.ID, HtmlTools.encodeId( release.getVersion() ) ); - sink.sectionTitle( Sink.SECTION_LEVEL_2, attrs ); - sink.text( bundle.getString( "report.changes.label.release" ) + " " + release.getVersion() + date ); - sink.sectionTitle_( Sink.SECTION_LEVEL_2 ); + attrs.addAttribute(SinkEventAttributes.ID, HtmlTools.encodeId(release.getVersion())); + sink.sectionTitle(Sink.SECTION_LEVEL_2, attrs); + sink.text(bundle.getString("report.changes.label.release") + " " + release.getVersion() + date); + sink.sectionTitle_(Sink.SECTION_LEVEL_2); - if ( isReleaseEmpty( release ) ) - { + if (isReleaseEmpty(release)) { sink.paragraph(); - sink.text( bundle.getString( "report.changes.text.no.changes" ) ); + sink.text(bundle.getString("report.changes.text.no.changes")); sink.paragraph_(); - } - else - { + } else { sink.table(); sink.tableRow(); - sinkHeader( sink, bundle.getString( "report.issues.label.type" ) ); - sinkHeader( sink, bundle.getString( "report.issues.label.summary" ) ); - sinkHeader( sink, bundle.getString( "report.issues.label.assignee" ) ); - if ( this.isAddActionDate() ) - { - sinkHeader( sink, bundle.getString( "report.issues.label.updated" ) ); + sinkHeader(sink, bundle.getString("report.issues.label.type")); + sinkHeader(sink, bundle.getString("report.issues.label.summary")); + sinkHeader(sink, bundle.getString("report.issues.label.assignee")); + if (this.isAddActionDate()) { + sinkHeader(sink, bundle.getString("report.issues.label.updated")); } sink.tableRow_(); - for ( Action action : release.getActions() ) - { - constructAction( sink, bundle, action ); + for (Action action : release.getActions()) { + constructAction(sink, bundle, action); } - for ( Object o : release.getComponents() ) - { + for (Object o : release.getComponents()) { Component component = (Component) o; - constructComponent( sink, bundle, component ); + constructComponent(sink, bundle, component); } sink.table_(); @@ -568,33 +493,29 @@ private void constructRelease( Sink sink, ResourceBundle bundle, Release release * @param bundle Resource bundle * @param component Release component to generate content for. */ - private void constructComponent( Sink sink, ResourceBundle bundle, Component component ) - { - if ( !component.getActions().isEmpty() ) - { + private void constructComponent(Sink sink, ResourceBundle bundle, Component component) { + if (!component.getActions().isEmpty()) { sink.tableRow(); sink.tableHeaderCell(); sink.tableHeaderCell_(); sink.tableHeaderCell(); - sink.text( component.getName() ); + sink.text(component.getName()); sink.tableHeaderCell_(); sink.tableHeaderCell(); sink.tableHeaderCell_(); - if ( isAddActionDate() ) - { + if (isAddActionDate()) { sink.tableHeaderCell(); sink.tableHeaderCell_(); } sink.tableRow_(); - for ( Action action : component.getActions() ) - { - constructAction( sink, bundle, action ); + for (Action action : component.getActions()) { + constructAction(sink, bundle, action); } } } @@ -605,18 +526,14 @@ private void constructComponent( Sink sink, ResourceBundle bundle, Component com * @param release Release to check * @return true if release doesn't contain any issues, false otherwise */ - private boolean isReleaseEmpty( Release release ) - { - if ( !release.getActions().isEmpty() ) - { + private boolean isReleaseEmpty(Release release) { + if (!release.getActions().isEmpty()) { return false; } - for ( Object o : release.getComponents() ) - { + for (Object o : release.getComponents()) { Component component = (Component) o; - if ( !component.getActions().isEmpty() ) - { + if (!component.getActions().isEmpty()) { return false; } } @@ -631,18 +548,15 @@ private boolean isReleaseEmpty( Release release ) * @param system The issue management system * @return An interpolated issue link */ - private String parseIssueLink( String issue, String system ) - { + private String parseIssueLink(String issue, String system) { String parseLink; - String issueLink = this.issueLinksPerSystem.get( system ); - parseLink = issueLink.replaceFirst( ISSUE_TOKEN, issue ); - if ( parseLink.contains( URL_TOKEN ) ) - { - String url = this.url.substring( 0, this.url.lastIndexOf( "/" ) ); - parseLink = parseLink.replaceFirst( URL_TOKEN, url ); + String issueLink = this.issueLinksPerSystem.get(system); + parseLink = issueLink.replaceFirst(ISSUE_TOKEN, issue); + if (parseLink.contains(URL_TOKEN)) { + String url = this.url.substring(0, this.url.lastIndexOf("/")); + parseLink = parseLink.replaceFirst(URL_TOKEN, url); } return parseLink; } - } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesValidatorMojo.java b/src/main/java/org/apache/maven/plugins/changes/ChangesValidatorMojo.java index b79e353b..469c3bef 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesValidatorMojo.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesValidatorMojo.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.io.File; import java.util.List; @@ -33,96 +32,78 @@ /** * Goal which validate the changes.xml file. - * + * * @author Olivier Lamy * @version $Id$ * @since 2.1 */ -@Mojo( name = "changes-validate", threadSafe = true ) -public class ChangesValidatorMojo - extends AbstractChangesMojo -{ +@Mojo(name = "changes-validate", threadSafe = true) +public class ChangesValidatorMojo extends AbstractChangesMojo { /** */ - @Component( role = ChangesSchemaValidator.class, hint = "default" ) + @Component(role = ChangesSchemaValidator.class, hint = "default") private ChangesSchemaValidator changesSchemaValidator; /** * The changes xsd version. */ - @Parameter( property = "changes.xsdVersion", defaultValue = "1.0.0" ) + @Parameter(property = "changes.xsdVersion", defaultValue = "1.0.0") private String changesXsdVersion; /** * Mojo failure if validation failed. If not and validation failed only a warning will be logged. */ - @Parameter( property = "changes.validate.failed", defaultValue = "false" ) + @Parameter(property = "changes.validate.failed", defaultValue = "false") private boolean failOnError; /** * The path of the changes.xml file that will be converted into an HTML report. */ - @Parameter( property = "changes.xmlPath", defaultValue = "src/changes/changes.xml" ) + @Parameter(property = "changes.xmlPath", defaultValue = "src/changes/changes.xml") private File xmlPath; /** * @see org.apache.maven.plugin.Mojo#execute() */ - public void execute() - throws MojoExecutionException - { + public void execute() throws MojoExecutionException { // Run only at the execution root - if ( runOnlyAtExecutionRoot && !isThisTheExecutionRoot() ) - { - getLog().info( "Skipping the changes validate in this project because it's not the Execution Root" ); - } - else - { - if ( !xmlPath.exists() ) - { - getLog().warn( "changes.xml file " + xmlPath.getAbsolutePath() + " does not exist." ); + if (runOnlyAtExecutionRoot && !isThisTheExecutionRoot()) { + getLog().info("Skipping the changes validate in this project because it's not the Execution Root"); + } else { + if (!xmlPath.exists()) { + getLog().warn("changes.xml file " + xmlPath.getAbsolutePath() + " does not exist."); return; } - try - { + try { XmlValidationHandler xmlValidationHandler = - changesSchemaValidator.validateXmlWithSchema( xmlPath, changesXsdVersion, failOnError ); + changesSchemaValidator.validateXmlWithSchema(xmlPath, changesXsdVersion, failOnError); boolean hasErrors = !xmlValidationHandler.getErrors().isEmpty(); - if ( hasErrors ) - { - logSchemaValidation( xmlValidationHandler.getErrors() ); - if ( failOnError ) - { - throw new MojoExecutionException( "changes.xml file " + xmlPath.getAbsolutePath() - + " is not valid, see previous errors." ); - } - else - { - getLog().info( " skip previous validation errors due to failOnError=false." ); + if (hasErrors) { + logSchemaValidation(xmlValidationHandler.getErrors()); + if (failOnError) { + throw new MojoExecutionException("changes.xml file " + xmlPath.getAbsolutePath() + + " is not valid, see previous errors."); + } else { + getLog().info(" skip previous validation errors due to failOnError=false."); } } - } - catch ( SchemaValidatorException e ) - { - if ( failOnError ) - { - throw new MojoExecutionException( "failed to validate changes.xml file " + xmlPath.getAbsolutePath() - + ": " + e.getMessage(), e ); + } catch (SchemaValidatorException e) { + if (failOnError) { + throw new MojoExecutionException( + "failed to validate changes.xml file " + xmlPath.getAbsolutePath() + ": " + e.getMessage(), + e); } } } } - private void logSchemaValidation( List errors ) - { - getLog().warn( "failed to validate changes.xml file " + xmlPath.getAbsolutePath() ); - getLog().warn( "validation errors: " ); - for ( SAXParseException error : errors ) - { - getLog().warn( error.getMessage() ); + private void logSchemaValidation(List errors) { + getLog().warn("failed to validate changes.xml file " + xmlPath.getAbsolutePath()); + getLog().warn("validation errors: "); + for (SAXParseException error : errors) { + getLog().warn(error.getMessage()); } } - } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesXML.java b/src/main/java/org/apache/maven/plugins/changes/ChangesXML.java index 5fe79597..323fa16b 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesXML.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesXML.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,31 +16,13 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.io.File; import java.io.FileInputStream; import java.util.Collections; import java.util.List; -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.changes.model.Body; import org.apache.maven.plugins.changes.model.ChangesDocument; @@ -55,8 +35,7 @@ * * @version $Id$ */ -public class ChangesXML -{ +public class ChangesXML { /** The list of releases in the changes.xml file. */ private List releaseList; @@ -75,43 +54,35 @@ public class ChangesXML /** * Constructor that sets the changes.xml file and the logger. - * + * * @param xmlPath the changes.xml file * @param log the logger * @throws ChangesXMLRuntimeException if there was a fatal error while parsing the changes.xml file */ - public ChangesXML( File xmlPath, Log log ) - throws ChangesXMLRuntimeException - { + public ChangesXML(File xmlPath, Log log) throws ChangesXMLRuntimeException { - if ( xmlPath == null || !xmlPath.exists() ) - { - log.error( "changes xml file is null or not exists " ); + if (xmlPath == null || !xmlPath.exists()) { + log.error("changes xml file is null or not exists "); return; } - try - { + try { ChangesXpp3Reader reader = new ChangesXpp3Reader(); - try ( FileInputStream fileInputStream = new FileInputStream( xmlPath ) ) - { - changesDocument = reader.read( fileInputStream, false ); + try (FileInputStream fileInputStream = new FileInputStream(xmlPath)) { + changesDocument = reader.read(fileInputStream, false); } - if ( changesDocument == null ) - { - log.error( "Cannot build Changes Report from file: " + xmlPath.getPath() ); + if (changesDocument == null) { + log.error("Cannot build Changes Report from file: " + xmlPath.getPath()); return; } Properties properties = changesDocument.getProperties(); - if ( properties != null ) - { - if ( properties.getAuthor() != null ) - { + if (properties != null) { + if (properties.getAuthor() != null) { this.author = properties.getAuthor().getName(); this.authorEmail = properties.getAuthor().getName(); } @@ -120,107 +91,94 @@ public ChangesXML( File xmlPath, Log log ) Body body = changesDocument.getBody(); - if ( body != null ) - { + if (body != null) { this.releaseList = body.getReleases(); } - } - catch ( Throwable e ) - { - log.error( "An error occurred when parsing the changes.xml file: ", e ); - throw new ChangesXMLRuntimeException( "An error occurred when parsing the changes.xml file", e ); + } catch (Throwable e) { + log.error("An error occurred when parsing the changes.xml file: ", e); + throw new ChangesXMLRuntimeException("An error occurred when parsing the changes.xml file", e); } } /** * Sets the {@link ChangesXML#author} attribute. - * + * * @param author the new value of the {@link ChangesXML#author} attribute */ - public void setAuthor( String author ) - { + public void setAuthor(String author) { this.author = author; } /** * Returns the current value of the author attribute. - * + * * @return the current value of the author attribute */ - public String getAuthor() - { + public String getAuthor() { return author; } /** * Sets the {@link ChangesXML#releaseList} attribute. - * + * * @param releaseList the new value of the {@link ChangesXML#releaseList} attribute */ - public void setReleaseList( List releaseList ) - { + public void setReleaseList(List releaseList) { this.releaseList = releaseList; } /** * Returns the current value of the {@link ChangesXML#releaseList} attribute. - * + * * @return the current value of the {@link ChangesXML#releaseList} attribute */ - public List getReleaseList() - { + public List getReleaseList() { return releaseList == null ? Collections.emptyList() : releaseList; } /** * Sets the {@link ChangesXML#title} attribute. - * + * * @param title the new value of the {@link ChangesXML#title} attribute */ - public void setTitle( String title ) - { + public void setTitle(String title) { this.title = title; } /** * Returns the current value of the {@link ChangesXML#title} attribute. - * + * * @return the current value of the {@link ChangesXML#title} attribute */ - public String getTitle() - { + public String getTitle() { return title; } /** * Returns the current value of the {@link ChangesXML#changesDocument} attribute. - * + * * @return the current value of the {@link ChangesXML#changesDocument} attribute */ - public ChangesDocument getChangesDocument() - { + public ChangesDocument getChangesDocument() { return changesDocument; } /** * Returns the current value of the {@link ChangesXML#authorEmail} attribute. - * + * * @return the current value of the {@link ChangesXML#authorEmail} attribute */ - public String getAuthorEmail() - { + public String getAuthorEmail() { return authorEmail; } /** * Sets the {@link ChangesXML#authorEmail} attribute. - * + * * @param authorEmail the new value of the {@link ChangesXML#authorEmail} attribute */ - public void setAuthorEmail( String authorEmail ) - { + public void setAuthorEmail(String authorEmail) { this.authorEmail = authorEmail; } - } diff --git a/src/main/java/org/apache/maven/plugins/changes/ChangesXMLRuntimeException.java b/src/main/java/org/apache/maven/plugins/changes/ChangesXMLRuntimeException.java index 61620980..62639336 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ChangesXMLRuntimeException.java +++ b/src/main/java/org/apache/maven/plugins/changes/ChangesXMLRuntimeException.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; /** * This is a runtime exception class that is thrown by the @@ -26,9 +25,7 @@ * * @author Gabor Szabo */ -public class ChangesXMLRuntimeException - extends RuntimeException -{ +public class ChangesXMLRuntimeException extends RuntimeException { /** The serialVersionUID **/ private static final long serialVersionUID = -8059557047280992301L; @@ -37,9 +34,8 @@ public class ChangesXMLRuntimeException * * @param msg the exception message. */ - public ChangesXMLRuntimeException( String msg ) - { - super( msg ); + public ChangesXMLRuntimeException(String msg) { + super(msg); } /** @@ -48,8 +44,7 @@ public ChangesXMLRuntimeException( String msg ) * @param msg the exception message. * @param cause the cause. */ - public ChangesXMLRuntimeException( String msg, Throwable cause ) - { - super( msg, cause ); + public ChangesXMLRuntimeException(String msg, Throwable cause) { + super(msg, cause); } } diff --git a/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java b/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java index af0030ed..23cba0ba 100644 --- a/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java +++ b/src/main/java/org/apache/maven/plugins/changes/FeedGenerator.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,37 +16,33 @@ * specific language governing permissions and limitations * under the License. */ - -import com.sun.syndication.feed.synd.SyndContent; -import com.sun.syndication.feed.synd.SyndContentImpl; -import com.sun.syndication.feed.synd.SyndEntry; -import com.sun.syndication.feed.synd.SyndEntryImpl; -import com.sun.syndication.feed.synd.SyndFeed; -import com.sun.syndication.feed.synd.SyndFeedImpl; -import com.sun.syndication.io.FeedException; -import com.sun.syndication.io.SyndFeedOutput; +package org.apache.maven.plugins.changes; import java.io.IOException; import java.io.Writer; - import java.text.DateFormat; import java.text.ParseException; - import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; import java.util.ResourceBundle; +import com.sun.syndication.feed.synd.SyndContent; +import com.sun.syndication.feed.synd.SyndContentImpl; +import com.sun.syndication.feed.synd.SyndEntry; +import com.sun.syndication.feed.synd.SyndEntryImpl; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; import org.apache.maven.doxia.util.HtmlTools; - import org.apache.maven.plugins.changes.model.Release; /** * @author ltheussl */ -public class FeedGenerator -{ +public class FeedGenerator { private final ResourceBundle rbundle; private final SyndFeed feed; @@ -66,10 +60,10 @@ public class FeedGenerator * * @param locale a locale for i18n. */ - public FeedGenerator( final Locale locale ) - { + public FeedGenerator(final Locale locale) { this.feed = new SyndFeedImpl(); - this.rbundle = ResourceBundle.getBundle( "changes-report", locale, this.getClass().getClassLoader() ); + this.rbundle = ResourceBundle.getBundle( + "changes-report", locale, this.getClass().getClassLoader()); } /** @@ -77,8 +71,7 @@ public FeedGenerator( final Locale locale ) * * @return the author. */ - public String getAuthor() - { + public String getAuthor() { return author; } @@ -87,8 +80,7 @@ public String getAuthor() * * @param author not null. */ - public void setAuthor( final String author ) - { + public void setAuthor(final String author) { this.author = author.trim(); // this also assures that author is not null. } @@ -97,8 +89,7 @@ public void setAuthor( final String author ) * * @return the title. */ - public String getTitle() - { + public String getTitle() { return title; } @@ -107,8 +98,7 @@ public String getTitle() * * @param title not null. */ - public void setTitle( final String title ) - { + public void setTitle(final String title) { this.title = title.trim(); // this also assures that title is not null. } @@ -117,8 +107,7 @@ public void setTitle( final String title ) * * @return may be null. */ - public DateFormat getDateFormat() - { + public DateFormat getDateFormat() { return dateFormat; } @@ -127,8 +116,7 @@ public DateFormat getDateFormat() * * @param dateFormat may be null. */ - public void setDateFormat( final DateFormat dateFormat ) - { + public void setDateFormat(final DateFormat dateFormat) { this.dateFormat = dateFormat; } @@ -137,8 +125,7 @@ public void setDateFormat( final DateFormat dateFormat ) * * @return the link. */ - public String getLink() - { + public String getLink() { return link; } @@ -147,8 +134,7 @@ public String getLink() * * @param link not null. */ - public void setLink( final String link ) - { + public void setLink(final String link) { this.link = link.trim(); // this also assures that link is not null. } @@ -160,9 +146,8 @@ public void setLink( final String link ) * @param type the feed type to check. May be null. * @return true if if the given type is supported by the rome library, false otherwise. */ - public boolean isSupportedFeedType( final String type ) - { - return getSupportedFeedTypes().contains( type ); + public boolean isSupportedFeedType(final String type) { + return getSupportedFeedTypes().contains(type); } /** @@ -171,9 +156,8 @@ public boolean isSupportedFeedType( final String type ) * @return a List of supported feed types. * @see #isSupportedFeedType(java.lang.String) */ - @SuppressWarnings( "unchecked" ) - public List getSupportedFeedTypes() - { + @SuppressWarnings("unchecked") + public List getSupportedFeedTypes() { return feed.getSupportedFeedTypes(); } @@ -186,87 +170,73 @@ public List getSupportedFeedTypes() * @param writer a Writer. Note that this is not flushed nor closed upon exit. * @throws IOException if an error occurs during export. */ - public void export( final List releases, final String feedType, final Writer writer ) - throws IOException - { - feed.setFeedType( feedType ); - feed.setTitle( title ); - feed.setAuthor( author ); - feed.setPublishedDate( new Date() ); - feed.setLink( link ); - feed.setDescription( rbundle.getString( "report.changes.text.rssfeed.description" ) ); - feed.setLanguage( rbundle.getLocale().getLanguage() ); + public void export(final List releases, final String feedType, final Writer writer) throws IOException { + feed.setFeedType(feedType); + feed.setTitle(title); + feed.setAuthor(author); + feed.setPublishedDate(new Date()); + feed.setLink(link); + feed.setDescription(rbundle.getString("report.changes.text.rssfeed.description")); + feed.setLanguage(rbundle.getLocale().getLanguage()); // feed.setCopyright( ); // feed.setEncoding(); - feed.setEntries( getEntries( releases ) ); + feed.setEntries(getEntries(releases)); - try - { - new SyndFeedOutput().output( feed, writer ); - } - catch ( FeedException ex ) - { - throw new IOException( ex.getMessage(), ex ); + try { + new SyndFeedOutput().output(feed, writer); + } catch (FeedException ex) { + throw new IOException(ex.getMessage(), ex); } } - private List getEntries( final List releases ) - { - final List entries = new ArrayList<>( 1 ); + private List getEntries(final List releases) { + final List entries = new ArrayList<>(1); - if ( releases.size() > 0 ) - { - final Release release = releases.get( 0 ); // TODO: is this guaranteed to be the latest? + if (releases.size() > 0) { + final Release release = releases.get(0); // TODO: is this guaranteed to be the latest? final SyndEntry entry = new SyndEntryImpl(); - entry.setTitle( release.getVersion() ); - entry.setLink( link + "#" + HtmlTools.encodeId( release.getVersion() ) ); - entry.setDescription( getSyndContent( release ) ); - entry.setPublishedDate( getDate( release.getDateRelease(), dateFormat ) ); + entry.setTitle(release.getVersion()); + entry.setLink(link + "#" + HtmlTools.encodeId(release.getVersion())); + entry.setDescription(getSyndContent(release)); + entry.setPublishedDate(getDate(release.getDateRelease(), dateFormat)); - entries.add( entry ); + entries.add(entry); } return entries; } - private static SyndContent getSyndContent( final Release release ) - { + private static SyndContent getSyndContent(final Release release) { final SyndContent syndContent = new SyndContentImpl(); - syndContent.setType( "text/html" ); + syndContent.setType("text/html"); - final StringBuilder sb = new StringBuilder( 512 ); + final StringBuilder sb = new StringBuilder(512); final String description = release.getDescription(); - if ( description != null && description.trim().length() > 0 ) - { - sb.append( "

" ).append( description ).append( "

" ); + if (description != null && description.trim().length() > 0) { + sb.append("

").append(description).append("

"); } // TODO: localize? - sb.append( "

Version " ).append( release.getVersion() ).append( " is available with " ); - sb.append( release.getActions().size() ).append( " fixed issues.

" ); + sb.append("

Version ").append(release.getVersion()).append(" is available with "); + sb.append(release.getActions().size()).append(" fixed issues.

"); - syndContent.setValue( sb.toString() ); + syndContent.setValue(sb.toString()); return syndContent; } - private static Date getDate( final String dateRelease, final DateFormat dateFormat ) - { - if ( dateFormat == null ) - { + private static Date getDate(final String dateRelease, final DateFormat dateFormat) { + if (dateFormat == null) { return new Date(); } - try - { - return dateFormat.parse( dateRelease ); - } - catch ( ParseException ex ) - { + try { + return dateFormat.parse(dateRelease); + } catch (ParseException ex) { return new Date(); } } -} \ No newline at end of file +} diff --git a/src/main/java/org/apache/maven/plugins/changes/IssueAdapter.java b/src/main/java/org/apache/maven/plugins/changes/IssueAdapter.java index ef090a33..5443e217 100644 --- a/src/main/java/org/apache/maven/plugins/changes/IssueAdapter.java +++ b/src/main/java/org/apache/maven/plugins/changes/IssueAdapter.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,17 +16,18 @@ * specific language governing permissions and limitations * under the License. */ - -import org.apache.maven.plugins.changes.model.Action; -import org.apache.maven.plugins.changes.model.Release; -import org.apache.maven.plugins.issues.Issue; -import org.apache.maven.plugins.issues.IssueManagementSystem; +package org.apache.maven.plugins.changes; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.apache.maven.plugins.changes.model.Action; +import org.apache.maven.plugins.changes.model.Release; +import org.apache.maven.plugins.issues.Issue; +import org.apache.maven.plugins.issues.IssueManagementSystem; + /** * An adapter that can adapt data models from other issue management system to the data models used in the changes.xml * file. @@ -37,8 +36,7 @@ * @version $Id$ * @since 2.4 */ -public class IssueAdapter -{ +public class IssueAdapter { private static final String UNKNOWN_ISSUE_TYPE = ""; private IssueManagementSystem ims; @@ -48,13 +46,11 @@ public class IssueAdapter * * @param ims The issue management system that has the data that should be adapted */ - public IssueAdapter( IssueManagementSystem ims ) - { + public IssueAdapter(IssueManagementSystem ims) { this.ims = ims; } - private Map getIssueTypeMap() - { + private Map getIssueTypeMap() { return ims.getIssueTypeMap(); } @@ -64,38 +60,33 @@ private Map getIssueTypeMap() * @param issues The issues * @return A list of releases */ - public List getReleases( List issues ) - { + public List getReleases(List issues) { // A Map of releases keyed by fixVersion Map releasesMap = new HashMap<>(); // Loop through all issues looking for fixVersions - for ( Issue issue : issues ) - { + for (Issue issue : issues) { // Do NOT create a release for issues that lack a fixVersion - if ( issue.getFixVersions() != null ) - { - for ( String fixVersion : issue.getFixVersions() ) - { + if (issue.getFixVersions() != null) { + for (String fixVersion : issue.getFixVersions()) { // Try to get a matching Release from the map - Release release = releasesMap.get( fixVersion ); - if ( release == null ) - { + Release release = releasesMap.get(fixVersion); + if (release == null) { // Add a new Release to the Map if it wasn't there release = new Release(); - release.setVersion( fixVersion ); - releasesMap.put( fixVersion, release ); + release.setVersion(fixVersion); + releasesMap.put(fixVersion, release); } // Add this issue as an Action to this release - Action action = createAction( issue ); - release.addAction( action ); + Action action = createAction(issue); + release.addAction(action); } } } // Extract the releases from the Map to a List - return new ArrayList<>( releasesMap.values() ); + return new ArrayList<>(releasesMap.values()); } /** @@ -104,31 +95,27 @@ public List getReleases( List issues ) * @param issue The issue to extract the information from * @return An Action */ - public Action createAction( Issue issue ) - { + public Action createAction(Issue issue) { Action action = new Action(); // @todo We need to add something like issue.getPresentationIdentifier() to be able to support other IMSes // beside JIRA - action.setIssue( issue.getKey() ); + action.setIssue(issue.getKey()); // Try to map the IMS-specific issue type to one that is used in a changes.xml file IssueType type; - if ( getIssueTypeMap().containsKey( issue.getType() ) ) - { - type = getIssueTypeMap().get( issue.getType() ); - action.setType( type.modelRepresentation() ); - } - else - { - action.setType( UNKNOWN_ISSUE_TYPE ); + if (getIssueTypeMap().containsKey(issue.getType())) { + type = getIssueTypeMap().get(issue.getType()); + action.setType(type.modelRepresentation()); + } else { + action.setType(UNKNOWN_ISSUE_TYPE); } - action.setDev( issue.getAssignee() ); + action.setDev(issue.getAssignee()); - action.setDueTo( issue.getReporter() == null ? "" : issue.getReporter() ); + action.setDueTo(issue.getReporter() == null ? "" : issue.getReporter()); - action.setAction( issue.getSummary() ); + action.setAction(issue.getSummary()); return action; } } diff --git a/src/main/java/org/apache/maven/plugins/changes/IssueType.java b/src/main/java/org/apache/maven/plugins/changes/IssueType.java index ed112d27..800f86ee 100644 --- a/src/main/java/org/apache/maven/plugins/changes/IssueType.java +++ b/src/main/java/org/apache/maven/plugins/changes/IssueType.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,42 +16,38 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; /** * The types of issues that can be used in a changes.xml file. * * @version $Id$ */ -public enum IssueType -{ - ADD( "add" ), FIX( "fix" ), UPDATE( "update" ), REMOVE( "remove" ); +public enum IssueType { + ADD("add"), + FIX("fix"), + UPDATE("update"), + REMOVE("remove"); private String configurationKey; - IssueType( String configurationKey ) - { + IssueType(String configurationKey) { this.configurationKey = configurationKey; } - public String configurationKey() - { + public String configurationKey() { return configurationKey; } - public String modelRepresentation() - { + public String modelRepresentation() { return name().toLowerCase(); } - public static IssueType lookupByKey( String key ) - { + public static IssueType lookupByKey(String key) { IssueType type; - try - { - type = IssueType.valueOf( key.toUpperCase() ); - } - catch ( IllegalArgumentException e ) - { + try { + type = IssueType.valueOf(key.toUpperCase()); + } catch (IllegalArgumentException e) { type = null; } return type; diff --git a/src/main/java/org/apache/maven/plugins/changes/ProjectUtils.java b/src/main/java/org/apache/maven/plugins/changes/ProjectUtils.java index e5f00c01..1b383d1a 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ProjectUtils.java +++ b/src/main/java/org/apache/maven/plugins/changes/ProjectUtils.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import org.apache.maven.project.MavenProject; @@ -28,12 +27,9 @@ * @version $Id$ * @since 2.4 */ -public final class ProjectUtils -{ +public final class ProjectUtils { - private ProjectUtils() - { - } + private ProjectUtils() {} /** * Check if the issue management system has been properly configured in the Maven project. @@ -44,23 +40,17 @@ private ProjectUtils() * @return null if the <issueManagement> element of the POM is complete, otherwise a String * containing the reason of the failed validation. */ - public static String validateIssueManagement( MavenProject project, String issueManagementSystem, - String mojoResult ) - { - if ( project.getIssueManagement() == null ) - { + public static String validateIssueManagement( + MavenProject project, String issueManagementSystem, String mojoResult) { + if (project.getIssueManagement() == null) { return "No Issue Management set. No " + mojoResult + " will be generated."; - } - else if ( ( project.getIssueManagement().getUrl() == null ) - || ( project.getIssueManagement().getUrl().trim().equals( "" ) ) ) - { + } else if ((project.getIssueManagement().getUrl() == null) + || (project.getIssueManagement().getUrl().trim().equals(""))) { return "No URL set in Issue Management. No " + mojoResult + " will be generated."; - } - else if ( ( project.getIssueManagement().getSystem() != null ) - && !( project.getIssueManagement().getSystem().equalsIgnoreCase( issueManagementSystem ) ) ) - { + } else if ((project.getIssueManagement().getSystem() != null) + && !(project.getIssueManagement().getSystem().equalsIgnoreCase(issueManagementSystem))) { return "The " + mojoResult + " only supports " + issueManagementSystem + ". No " + mojoResult - + " will be generated."; + + " will be generated."; } return null; } diff --git a/src/main/java/org/apache/maven/plugins/changes/ReleaseUtils.java b/src/main/java/org/apache/maven/plugins/changes/ReleaseUtils.java index fbf29f2b..482f8a8c 100644 --- a/src/main/java/org/apache/maven/plugins/changes/ReleaseUtils.java +++ b/src/main/java/org/apache/maven/plugins/changes/ReleaseUtils.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes; import java.util.ArrayList; import java.util.Collections; @@ -35,14 +34,12 @@ * @version $Id$ * @since 2.4 */ -public class ReleaseUtils -{ +public class ReleaseUtils { private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT"; private Log log; - public ReleaseUtils( Log log ) - { + public ReleaseUtils(Log log) { this.log = log; } @@ -54,29 +51,24 @@ public ReleaseUtils( Log log ) * @return A Release that matches the next release of the current project * @throws org.apache.maven.plugin.MojoExecutionException If a release can't be found */ - public Release getLatestRelease( List releases, String pomVersion ) - throws MojoExecutionException - { + public Release getLatestRelease(List releases, String pomVersion) throws MojoExecutionException { // Remove "-SNAPSHOT" from the end, if it's there - if ( pomVersion != null && pomVersion.endsWith( SNAPSHOT_SUFFIX ) ) - { - pomVersion = pomVersion.substring( 0, pomVersion.length() - SNAPSHOT_SUFFIX.length() ); + if (pomVersion != null && pomVersion.endsWith(SNAPSHOT_SUFFIX)) { + pomVersion = pomVersion.substring(0, pomVersion.length() - SNAPSHOT_SUFFIX.length()); } - getLog().debug( "Found " + releases.size() + " releases." ); + getLog().debug("Found " + releases.size() + " releases."); - Release release = getRelease( releases, pomVersion ); + Release release = getRelease(releases, pomVersion); - if ( release == null ) - { - throw new MojoExecutionException( "Couldn't find the release '" + pomVersion - + "' among the supplied releases: " + toString( releases ) ); + if (release == null) { + throw new MojoExecutionException("Couldn't find the release '" + pomVersion + + "' among the supplied releases: " + toString(releases)); } return release; } - private Log getLog() - { + private Log getLog() { return log; } @@ -87,22 +79,17 @@ private Log getLog() * @param version The version we want * @return A Release, or null if no release with the specified version can be found */ - protected Release getRelease( List releases, String version ) - { - for ( Release release : releases ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "The release: " + release.getVersion() + " has " + release.getActions().size() - + " actions." ); + protected Release getRelease(List releases, String version) { + for (Release release : releases) { + if (getLog().isDebugEnabled()) { + getLog().debug("The release: " + release.getVersion() + " has " + + release.getActions().size() + " actions."); } - if ( release.getVersion() != null && release.getVersion().equals( version ) ) - { - if ( getLog().isDebugEnabled() ) - { - getLog().debug( "Found the correct release: " + release.getVersion() ); - logRelease( release ); + if (release.getVersion() != null && release.getVersion().equals(version)) { + if (getLog().isDebugEnabled()) { + getLog().debug("Found the correct release: " + release.getVersion()); + logRelease(release); } return release; } @@ -110,16 +97,14 @@ protected Release getRelease( List releases, String version ) return null; } - protected void logRelease( Release release ) - { + protected void logRelease(Release release) { Action action; - for ( Action action1 : release.getActions() ) - { + for (Action action1 : release.getActions()) { action = action1; - getLog().debug( "o " + action.getType() ); - getLog().debug( "issue : " + action.getIssue() ); - getLog().debug( "action : " + action.getAction() ); - getLog().debug( "dueTo : " + action.getDueTo() ); + getLog().debug("o " + action.getType()); + getLog().debug("issue : " + action.getIssue()); + getLog().debug("action : " + action.getAction()); + getLog().debug("dueTo : " + action.getDueTo()); } } @@ -131,18 +116,14 @@ protected void logRelease( Release release ) * @param secondReleases Releases from the second issue tracker * @return A list containing the merged releases */ - public List mergeReleases( final List firstReleases, final List secondReleases ) - { - if ( firstReleases == null && secondReleases == null ) - { + public List mergeReleases(final List firstReleases, final List secondReleases) { + if (firstReleases == null && secondReleases == null) { return Collections.emptyList(); } - if ( firstReleases == null ) - { + if (firstReleases == null) { return secondReleases; } - if ( secondReleases == null ) - { + if (secondReleases == null) { return firstReleases; } @@ -151,26 +132,21 @@ public List mergeReleases( final List firstReleases, final Lis // Loop through the releases from the first issue tracker, merging in // actions from releases with the same version from the second issue // tracker - for ( Release firstRelease : firstReleases ) - { - Release secondRelease = getRelease( secondReleases, firstRelease.getVersion() ); - if ( secondRelease != null ) - { - if ( secondRelease.getActions() != null ) - { - firstRelease.getActions().addAll( secondRelease.getActions() ); + for (Release firstRelease : firstReleases) { + Release secondRelease = getRelease(secondReleases, firstRelease.getVersion()); + if (secondRelease != null) { + if (secondRelease.getActions() != null) { + firstRelease.getActions().addAll(secondRelease.getActions()); } } - mergedReleases.add( firstRelease ); + mergedReleases.add(firstRelease); } // Handle releases that are only in the second issue tracker - for ( Release secondRelease : secondReleases ) - { - Release mergedRelease = getRelease( mergedReleases, secondRelease.getVersion() ); - if ( mergedRelease == null ) - { - mergedReleases.add( secondRelease ); + for (Release secondRelease : secondReleases) { + Release mergedRelease = getRelease(mergedReleases, secondRelease.getVersion()); + if (mergedRelease == null) { + mergedReleases.add(secondRelease); } } return mergedReleases; @@ -186,64 +162,53 @@ public List mergeReleases( final List firstReleases, final Lis * @param componentReleases Releases from the child component * @return A list containing the merged releases */ - public List mergeReleases( final List releases, final String componentName, - final List componentReleases ) - { - if ( releases == null && componentReleases == null ) - { + public List mergeReleases( + final List releases, final String componentName, final List componentReleases) { + if (releases == null && componentReleases == null) { return Collections.emptyList(); } - if ( componentReleases == null ) - { + if (componentReleases == null) { return releases; } final List mergedReleases = new ArrayList<>(); - if ( releases != null ) - { - for ( Object release1 : releases ) - { + if (releases != null) { + for (Object release1 : releases) { final Release release = (Release) release1; - final Release componentRelease = getRelease( componentReleases, release.getVersion() ); - if ( componentRelease != null ) - { - release.addComponent( componentName, componentRelease ); + final Release componentRelease = getRelease(componentReleases, release.getVersion()); + if (componentRelease != null) { + release.addComponent(componentName, componentRelease); } - mergedReleases.add( release ); + mergedReleases.add(release); } } - for ( Object componentRelease1 : componentReleases ) - { + for (Object componentRelease1 : componentReleases) { final Release release = (Release) componentRelease1; - final Release mergedRelease = getRelease( mergedReleases, release.getVersion() ); - if ( mergedRelease == null ) - { + final Release mergedRelease = getRelease(mergedReleases, release.getVersion()); + if (mergedRelease == null) { final Release componentRelease = new Release(); - componentRelease.setVersion( release.getVersion() ); - componentRelease.setDateRelease( release.getDateRelease() ); - componentRelease.addComponent( componentName, release ); - mergedReleases.add( componentRelease ); + componentRelease.setVersion(release.getVersion()); + componentRelease.setDateRelease(release.getDateRelease()); + componentRelease.addComponent(componentName, release); + mergedReleases.add(componentRelease); } } return mergedReleases; } - private static String toString( Release release ) - { + private static String toString(Release release) { return release.getClass().getSimpleName() + "[version='" + release.getVersion() + "'" + ", date='" - + release.getDateRelease() + "'" + ", description='" + release.getDescription() + "'" + ", actionsSize=" - + release.getActions().size() + "]"; + + release.getDateRelease() + "'" + ", description='" + release.getDescription() + "'" + ", actionsSize=" + + release.getActions().size() + "]"; } - public static String toString( List releases ) - { - List releaseStrings = new ArrayList<>( releases.size() ); - for ( Release release : releases ) - { - releaseStrings.add( toString( release ) ); + public static String toString(List releases) { + List releaseStrings = new ArrayList<>(releases.size()); + for (Release release : releases) { + releaseStrings.add(toString(release)); } return releaseStrings.toString(); } diff --git a/src/main/java/org/apache/maven/plugins/changes/schema/ChangesSchemaValidator.java b/src/main/java/org/apache/maven/plugins/changes/schema/ChangesSchemaValidator.java index 4fc564d6..e3e4d0b1 100644 --- a/src/main/java/org/apache/maven/plugins/changes/schema/ChangesSchemaValidator.java +++ b/src/main/java/org/apache/maven/plugins/changes/schema/ChangesSchemaValidator.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes.schema; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes.schema; import java.io.File; @@ -26,8 +25,7 @@ * @since 28 juil. 2008 * @version $Id$ */ -public interface ChangesSchemaValidator -{ +public interface ChangesSchemaValidator { /** * @param file File to validate. * @param schemaVersion Schema version. @@ -35,7 +33,6 @@ public interface ChangesSchemaValidator * @return {@link XmlValidationHandler} * @throws SchemaValidatorException if validation failed. */ - XmlValidationHandler validateXmlWithSchema( File file, String schemaVersion, boolean failOnValidationError ) - throws SchemaValidatorException; - + XmlValidationHandler validateXmlWithSchema(File file, String schemaVersion, boolean failOnValidationError) + throws SchemaValidatorException; } diff --git a/src/main/java/org/apache/maven/plugins/changes/schema/DefaultChangesSchemaValidator.java b/src/main/java/org/apache/maven/plugins/changes/schema/DefaultChangesSchemaValidator.java index 068f34a6..ead9eb29 100644 --- a/src/main/java/org/apache/maven/plugins/changes/schema/DefaultChangesSchemaValidator.java +++ b/src/main/java/org/apache/maven/plugins/changes/schema/DefaultChangesSchemaValidator.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes.schema; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes.schema; + +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; import java.io.File; import java.io.IOException; @@ -26,11 +30,6 @@ import java.util.HashMap; import java.util.Map; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; - import org.apache.commons.io.input.XmlStreamReader; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.IOUtil; @@ -41,10 +40,8 @@ * @since 28 juil. 2008 * @version $Id$ */ -@Component( role = ChangesSchemaValidator.class, hint = "default" ) -public class DefaultChangesSchemaValidator - implements ChangesSchemaValidator -{ +@Component(role = ChangesSchemaValidator.class, hint = "default") +public class DefaultChangesSchemaValidator implements ChangesSchemaValidator { /** property schema */ public static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; @@ -53,52 +50,40 @@ public class DefaultChangesSchemaValidator private Map compiledSchemas = new HashMap<>(); - public XmlValidationHandler validateXmlWithSchema( File file, String schemaVersion, boolean failOnValidationError ) - throws SchemaValidatorException - { - try - { + public XmlValidationHandler validateXmlWithSchema(File file, String schemaVersion, boolean failOnValidationError) + throws SchemaValidatorException { + try { String schemaPath = CHANGES_SCHEMA_PATH + "changes-" + schemaVersion + ".xsd"; - Schema schema = getSchema( schemaPath ); + Schema schema = getSchema(schemaPath); Validator validator = schema.newValidator(); - XmlValidationHandler baseHandler = new XmlValidationHandler( failOnValidationError ); + XmlValidationHandler baseHandler = new XmlValidationHandler(failOnValidationError); - validator.setErrorHandler( baseHandler ); + validator.setErrorHandler(baseHandler); - try ( Reader reader = new XmlStreamReader( file ) ) - { - validator.validate( new StreamSource( reader ) ); + try (Reader reader = new XmlStreamReader(file)) { + validator.validate(new StreamSource(reader)); } return baseHandler; - } - catch ( IOException e ) - { - throw new SchemaValidatorException( "IOException : " + e.getMessage(), e ); - } - catch ( SAXException e ) - { - throw new SchemaValidatorException( "SAXException : " + e.getMessage(), e ); - } - catch ( Exception e ) - { - throw new SchemaValidatorException( "Exception : " + e.getMessage(), e ); + } catch (IOException e) { + throw new SchemaValidatorException("IOException : " + e.getMessage(), e); + } catch (SAXException e) { + throw new SchemaValidatorException("SAXException : " + e.getMessage(), e); + } catch (Exception e) { + throw new SchemaValidatorException("Exception : " + e.getMessage(), e); } } - public Schema getSchema( String schemaPath ) - throws SAXException, IOException - { - if ( this.compiledSchemas.containsKey( schemaPath ) ) - { - return this.compiledSchemas.get( schemaPath ); + public Schema getSchema(String schemaPath) throws SAXException, IOException { + if (this.compiledSchemas.containsKey(schemaPath)) { + return this.compiledSchemas.get(schemaPath); } - Schema schema = this.compileJAXPSchema( schemaPath ); + Schema schema = this.compileJAXPSchema(schemaPath); - this.compiledSchemas.put( schemaPath, schema ); + this.compiledSchemas.put(schemaPath, schema); return schema; } @@ -108,45 +93,31 @@ public Schema getSchema( String schemaPath ) * @return Schema * @throws Exception */ - private Schema compileJAXPSchema( String uriSchema ) - throws IOException, SAXException, NullPointerException - { + private Schema compileJAXPSchema(String uriSchema) throws IOException, SAXException, NullPointerException { InputStream in = null; - try - { - in = Thread.currentThread().getContextClassLoader().getResourceAsStream( uriSchema ); - if ( in == null ) - { - throw new NullPointerException( " impossible to load schema with path " + uriSchema ); + try { + in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uriSchema); + if (in == null) { + throw new NullPointerException(" impossible to load schema with path " + uriSchema); } - //newInstance de SchemaFactory not ThreadSafe - final Schema schema = SchemaFactory.newInstance( W3C_XML_SCHEMA ).newSchema( new StreamSource( in ) ); + // newInstance de SchemaFactory not ThreadSafe + final Schema schema = SchemaFactory.newInstance(W3C_XML_SCHEMA).newSchema(new StreamSource(in)); in.close(); in = null; return schema; - } - finally - { - IOUtil.close( in ); + } finally { + IOUtil.close(in); } } - public void loadSchema( String uriSchema ) - throws SchemaValidatorException - { - try - { - this.getSchema( uriSchema ); - } - catch ( SAXException e ) - { - throw new SchemaValidatorException( "SAXException : " + e.getMessage(), e ); + public void loadSchema(String uriSchema) throws SchemaValidatorException { + try { + this.getSchema(uriSchema); + } catch (SAXException e) { + throw new SchemaValidatorException("SAXException : " + e.getMessage(), e); + } catch (IOException e) { + throw new SchemaValidatorException("IOException : " + e.getMessage(), e); } - catch ( IOException e ) - { - throw new SchemaValidatorException( "IOException : " + e.getMessage(), e ); - } - } } diff --git a/src/main/java/org/apache/maven/plugins/changes/schema/SchemaValidatorException.java b/src/main/java/org/apache/maven/plugins/changes/schema/SchemaValidatorException.java index e96ece84..be238442 100644 --- a/src/main/java/org/apache/maven/plugins/changes/schema/SchemaValidatorException.java +++ b/src/main/java/org/apache/maven/plugins/changes/schema/SchemaValidatorException.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes.schema; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,15 +16,14 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes.schema; /** * @author Olivier Lamy * @since 28 juil. 2008 * @version $Id$ */ -public class SchemaValidatorException - extends Exception -{ +public class SchemaValidatorException extends Exception { /** * Generated serial UID. @@ -37,9 +34,7 @@ public class SchemaValidatorException * @param message Message. * @param cause Cause. */ - public SchemaValidatorException( String message, Throwable cause ) - { - super( message, cause ); + public SchemaValidatorException(String message, Throwable cause) { + super(message, cause); } - } diff --git a/src/main/java/org/apache/maven/plugins/changes/schema/XmlValidationHandler.java b/src/main/java/org/apache/maven/plugins/changes/schema/XmlValidationHandler.java index b7ae15ff..40bb18d1 100644 --- a/src/main/java/org/apache/maven/plugins/changes/schema/XmlValidationHandler.java +++ b/src/main/java/org/apache/maven/plugins/changes/schema/XmlValidationHandler.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.changes.schema; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -9,7 +7,7 @@ * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -18,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.changes.schema; import java.util.ArrayList; import java.util.List; @@ -32,10 +31,8 @@ * @since 28 juil. 2008 * @version $Id$ */ -public class XmlValidationHandler - extends DefaultHandler -{ - +public class XmlValidationHandler extends DefaultHandler { + private boolean parsingError = false; private List errors = new ArrayList<>(); @@ -49,97 +46,80 @@ public class XmlValidationHandler /** * @param failOnValidationError If fail on validation error. */ - public XmlValidationHandler( boolean failOnValidationError ) - { + public XmlValidationHandler(boolean failOnValidationError) { this.failOnValidationError = failOnValidationError; } /** * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException) */ - public void error( SAXParseException excp ) - throws SAXException - { - this.setErrorParsing( true ); - this.errors.add( excp ); - if ( this.failOnValidationError ) - { - throw new SAXException( excp.getMessage(), excp ); + public void error(SAXParseException excp) throws SAXException { + this.setErrorParsing(true); + this.errors.add(excp); + if (this.failOnValidationError) { + throw new SAXException(excp.getMessage(), excp); } } /** * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException) */ - public void fatalError( SAXParseException excp ) - throws SAXException - { - this.fatalErrors.add( excp ); - if ( this.failOnValidationError ) - { - throw new SAXException( excp.getMessage(), excp ); + public void fatalError(SAXParseException excp) throws SAXException { + this.fatalErrors.add(excp); + if (this.failOnValidationError) { + throw new SAXException(excp.getMessage(), excp); } } /** * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException) */ - public void warning( SAXParseException excp ) - { - this.warnings.add( excp ); + public void warning(SAXParseException excp) { + this.warnings.add(excp); } /** * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes) */ - public void startElement( String uri, String localName, String qName, Attributes attributes ) - { + public void startElement(String uri, String localName, String qName, Attributes attributes) { // nothing } /** * @return Returns the errorParsing. */ - public boolean isErrorParsing() - { + public boolean isErrorParsing() { return this.parsingError; } /** * @param error The errorParsing to set. */ - public void setErrorParsing( boolean error ) - { + public void setErrorParsing(boolean error) { this.parsingError = error; } - public List getErrors() - { + public List getErrors() { return errors; } - public void setErrors( List errors ) - { + public void setErrors(List errors) { this.errors = errors; } - public List getFatalErrors() - { + public List getFatalErrors() { return fatalErrors; } - public void setFatalErrors( List fatalErrors ) - { + public void setFatalErrors(List fatalErrors) { this.fatalErrors = fatalErrors; } - public List getWarnings() - { + public List getWarnings() { return warnings; } - public void setWarnings( List warnings ) - { + public void setWarnings(List warnings) { this.warnings = warnings; } } diff --git a/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java b/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java index cdd3a782..410deab0 100644 --- a/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java +++ b/src/main/java/org/apache/maven/plugins/github/GitHubDownloader.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.github; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,15 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.github; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.issues.Issue; @@ -32,19 +39,10 @@ import org.eclipse.egit.github.core.client.GitHubClient; import org.eclipse.egit.github.core.service.IssueService; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * @since 2.8 */ -public class GitHubDownloader -{ +public class GitHubDownloader { /** * The github client. @@ -76,175 +74,148 @@ public class GitHubDownloader */ private String githubIssueURL; - public GitHubDownloader( MavenProject project, String githubScheme, int githubPort, boolean includeOpenIssues, - boolean onlyMilestoneIssues ) - throws MalformedURLException - { + public GitHubDownloader( + MavenProject project, + String githubScheme, + int githubPort, + boolean includeOpenIssues, + boolean onlyMilestoneIssues) + throws MalformedURLException { this.includeOpenIssues = includeOpenIssues; this.onlyMilestoneIssues = onlyMilestoneIssues; - URL githubURL = new URL( project.getIssueManagement().getUrl() ); + URL githubURL = new URL(project.getIssueManagement().getUrl()); // The githubclient prefers to connect to 'github.com' using the api domain, unlike github enterprise // which can connect fine using its domain, so for github.com use empty constructor - if ( githubURL.getHost().equalsIgnoreCase( "github.com" ) ) - { + if (githubURL.getHost().equalsIgnoreCase("github.com")) { this.client = new GitHubClient(); - } - else - { - this.client = new GitHubClient( githubURL.getHost(), githubPort, githubScheme ); + } else { + this.client = new GitHubClient(githubURL.getHost(), githubPort, githubScheme); } this.githubIssueURL = project.getIssueManagement().getUrl(); - if ( !this.githubIssueURL.endsWith( "/" ) ) - { + if (!this.githubIssueURL.endsWith("/")) { this.githubIssueURL = this.githubIssueURL + "/"; } String urlPath = githubURL.getPath(); - if ( urlPath.startsWith( "/" ) ) - { - urlPath = urlPath.substring( 1 ); + if (urlPath.startsWith("/")) { + urlPath = urlPath.substring(1); } - if ( urlPath.endsWith( "/" ) ) - { - urlPath = urlPath.substring( 0, urlPath.length() - 2 ); + if (urlPath.endsWith("/")) { + urlPath = urlPath.substring(0, urlPath.length() - 2); } - String[] urlPathParts = urlPath.split( "/" ); + String[] urlPathParts = urlPath.split("/"); - if ( urlPathParts.length != 3 ) - { - throw new MalformedURLException( "GitHub issue management URL must look like, " - + "[GITHUB_DOMAIN]/[OWNER]/[REPO]/issues" ); + if (urlPathParts.length != 3) { + throw new MalformedURLException( + "GitHub issue management URL must look like, " + "[GITHUB_DOMAIN]/[OWNER]/[REPO]/issues"); } this.githubOwner = urlPathParts[0]; this.githubRepo = urlPathParts[1]; } - protected Issue createIssue( org.eclipse.egit.github.core.Issue githubIssue ) - { + protected Issue createIssue(org.eclipse.egit.github.core.Issue githubIssue) { Issue issue = new Issue(); - issue.setKey( String.valueOf( githubIssue.getNumber() ) ); - issue.setId( String.valueOf( githubIssue.getNumber() ) ); + issue.setKey(String.valueOf(githubIssue.getNumber())); + issue.setId(String.valueOf(githubIssue.getNumber())); - issue.setLink( this.githubIssueURL + githubIssue.getNumber() ); + issue.setLink(this.githubIssueURL + githubIssue.getNumber()); - issue.setCreated( githubIssue.getCreatedAt() ); + issue.setCreated(githubIssue.getCreatedAt()); - issue.setUpdated( githubIssue.getUpdatedAt() ); + issue.setUpdated(githubIssue.getUpdatedAt()); - if ( githubIssue.getAssignee() != null ) - { - if ( githubIssue.getAssignee().getName() != null ) - { - issue.setAssignee( githubIssue.getAssignee().getName() ); - } - else - { - issue.setAssignee( githubIssue.getAssignee().getLogin() ); + if (githubIssue.getAssignee() != null) { + if (githubIssue.getAssignee().getName() != null) { + issue.setAssignee(githubIssue.getAssignee().getName()); + } else { + issue.setAssignee(githubIssue.getAssignee().getLogin()); } } - issue.setTitle( githubIssue.getTitle() ); + issue.setTitle(githubIssue.getTitle()); - issue.setSummary( githubIssue.getTitle() ); + issue.setSummary(githubIssue.getTitle()); - if ( githubIssue.getMilestone() != null ) - { - issue.addFixVersion( githubIssue.getMilestone().getTitle() ); + if (githubIssue.getMilestone() != null) { + issue.addFixVersion(githubIssue.getMilestone().getTitle()); } - issue.setReporter( githubIssue.getUser().getLogin() ); + issue.setReporter(githubIssue.getUser().getLogin()); - if ( githubIssue.getClosedAt() != null ) - { - issue.setStatus( "closed" ); - } - else - { - issue.setStatus( "open" ); + if (githubIssue.getClosedAt() != null) { + issue.setStatus("closed"); + } else { + issue.setStatus("open"); } List