Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java?rev=1705359&r1=1705358&r2=1705359&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java Fri Sep 25 21:53:36 2015 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.ide; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,7 +18,6 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.ide; import java.io.File; import java.io.IOException; @@ -71,12 +72,12 @@ import org.codehaus.plexus.logging.Logge * the getters needed to get the various configuration flags and required components. The lifecycle: * * <pre> - * *** calls setup() where you can configure your specific stuff and stop the mojo from execute if appropriate *** - * - manually resolve project dependencies, NOT failing if a dependency is missing - * - compute project references (reactor projects) if the getUseProjectReferences() flag is set - * - download sources/javadocs if the getDownloadSources() flag is set - * *** calls writeConfiguration(), passing the list of resolved referenced dependencies *** - * - report the list of missing sources or just tell how to turn this feature on if the flag was disabled + * *** calls setup() where you can configure your specific stuff and stop the mojo from execute if appropriate *** + * - manually resolve project dependencies, NOT failing if a dependency is missing + * - compute project references (reactor projects) if the getUseProjectReferences() flag is set + * - download sources/javadocs if the getDownloadSources() flag is set + * *** calls writeConfiguration(), passing the list of resolved referenced dependencies *** + * - report the list of missing sources or just tell how to turn this feature on if the flag was disabled * </pre> * * @author Fabrizio Giustina @@ -179,8 +180,8 @@ public abstract class AbstractIdeSupport /** * Enables/disables the rechecking of the remote repository for downloading source/javadoc attachments. Defaults to * false. When this flag is <code>true</code> and the source or javadoc attachment has a status cache to indicate - * that it is not available, then the remote repository will be rechecked for a source or javadoc attachment and the - * status cache updated to reflect the new state. + * that it is not available, then the remote repository will be rechecked for a source or javadoc attachment and + * the status cache updated to reflect the new state. */ @Parameter( property = "forceRecheck" ) protected boolean forceRecheck; @@ -535,8 +536,7 @@ public abstract class AbstractIdeSupport catch ( ArtifactResolutionException e ) { getLog().debug( e.getMessage(), e ); - getLog().error( - Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { //$NON-NLS-1$ + getLog().error( Messages.getString( "AbstractIdeSupportMojo.artifactresolution", new Object[] { e.getGroupId(), e.getArtifactId(), e.getVersion(), e.getMessage() } ) ); @@ -550,44 +550,50 @@ public abstract class AbstractIdeSupport // keep track of added reactor projects in order to avoid duplicates Set emittedReactorProjectId = new HashSet(); - for (Object o : artifactResolutionResult.getArtifactResolutionNodes()) { + for ( Object o : artifactResolutionResult.getArtifactResolutionNodes() ) + { ResolutionNode node = (ResolutionNode) o; int dependencyDepth = node.getDepth(); Artifact art = node.getArtifact(); // don't resolve jars for reactor projects - if (hasToResolveJar(art)) { - try { - artifactResolver.resolve(art, node.getRemoteRepositories(), localRepository); - } catch (ArtifactNotFoundException e) { - getLog().debug(e.getMessage(), e); - getLog().warn( - Messages.getString( - "AbstractIdeSupportMojo.artifactdownload", new Object[]{ //$NON-NLS-1$ - e.getGroupId(), e.getArtifactId(), e.getVersion(), - e.getMessage()})); - } catch (ArtifactResolutionException e) { - getLog().debug(e.getMessage(), e); - getLog().warn( - Messages.getString( - "AbstractIdeSupportMojo.artifactresolution", new Object[]{ //$NON-NLS-1$ - e.getGroupId(), e.getArtifactId(), e.getVersion(), - e.getMessage()})); + if ( hasToResolveJar( art ) ) + { + try + { + artifactResolver.resolve( art, node.getRemoteRepositories(), localRepository ); + } + catch ( ArtifactNotFoundException e ) + { + getLog().debug( e.getMessage(), e ); + getLog().warn( Messages.getString( "AbstractIdeSupportMojo.artifactdownload", + new Object[] { e.getGroupId(), e.getArtifactId(), + e.getVersion(), e.getMessage() } ) ); + } + catch ( ArtifactResolutionException e ) + { + getLog().debug( e.getMessage(), e ); + getLog().warn( Messages.getString( "AbstractIdeSupportMojo.artifactresolution", + new Object[] { e.getGroupId(), e.getArtifactId(), + e.getVersion(), e.getMessage() } ) ); } } boolean includeArtifact = true; - if (getExcludes() != null) { + if ( getExcludes() != null ) + { String artifactFullId = art.getGroupId() + ":" + art.getArtifactId(); - if (getExcludes().contains(artifactFullId)) { - getLog().info("excluded: " + artifactFullId); + if ( getExcludes().contains( artifactFullId ) ) + { + getLog().info( "excluded: " + artifactFullId ); includeArtifact = false; } } - if (includeArtifact - && (!(getUseProjectReferences() && isAvailableAsAReactorProject(art)) || emittedReactorProjectId.add(art.getGroupId() - + '-' + art.getArtifactId()))) { + if ( includeArtifact + && ( !( getUseProjectReferences() && isAvailableAsAReactorProject( art ) ) + || emittedReactorProjectId.add( art.getGroupId() + '-' + art.getArtifactId() ) ) ) + { // the following doesn't work: art.getArtifactHandler().getPackaging() always returns "jar" // also @@ -604,25 +610,35 @@ public abstract class AbstractIdeSupport // an osgi bundle boolean isOsgiBundle; String osgiSymbolicName = null; - if (art.getFile() != null) { + if ( art.getFile() != null ) + { JarFile jarFile = null; - try { - jarFile = new JarFile(art.getFile(), false, ZipFile.OPEN_READ); + try + { + jarFile = new JarFile( art.getFile(), false, ZipFile.OPEN_READ ); Manifest manifest = jarFile.getManifest(); - if (manifest != null) { + if ( manifest != null ) + { osgiSymbolicName = - manifest.getMainAttributes().getValue( - new Attributes.Name( - "Bundle-SymbolicName")); + manifest.getMainAttributes().getValue( + new Attributes.Name( "Bundle-SymbolicName" ) ); } - } catch (IOException e) { - getLog().info("Unable to read jar manifest from " + art.getFile()); - } finally { - if (jarFile != null) { - try { + } + catch ( IOException e ) + { + getLog().info( "Unable to read jar manifest from " + art.getFile() ); + } + finally + { + if ( jarFile != null ) + { + try + { jarFile.close(); - } catch (IOException e) { + } + catch ( IOException e ) + { // ignore } } @@ -632,17 +648,18 @@ public abstract class AbstractIdeSupport isOsgiBundle = osgiSymbolicName != null; IdeDependency dep = - new IdeDependency(art.getGroupId(), art.getArtifactId(), art.getVersion(), - art.getClassifier(), useProjectReference(art), - Artifact.SCOPE_TEST.equals(art.getScope()), - Artifact.SCOPE_SYSTEM.equals(art.getScope()), - Artifact.SCOPE_PROVIDED.equals(art.getScope()), - art.getArtifactHandler().isAddedToClasspath(), art.getFile(), - art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, - getProjectNameForArifact(art)); + new IdeDependency( art.getGroupId(), art.getArtifactId(), art.getVersion(), + art.getClassifier(), useProjectReference( art ), + Artifact.SCOPE_TEST.equals( art.getScope() ), + Artifact.SCOPE_SYSTEM.equals( art.getScope() ), + Artifact.SCOPE_PROVIDED.equals( art.getScope() ), + art.getArtifactHandler().isAddedToClasspath(), art.getFile(), + art.getType(), isOsgiBundle, osgiSymbolicName, dependencyDepth, + getProjectNameForArifact( art ) ); // no duplicate entries allowed. System paths can cause this problem. - if (!dependencies.contains(dep)) { - dependencies.add(dep); + if ( !dependencies.contains( dep ) ) + { + dependencies.add( dep ); } } @@ -670,11 +687,11 @@ public abstract class AbstractIdeSupport * @param artifact The artifact to find the eclipse name for. * @return The name os the eclipse project. */ - abstract public String getProjectNameForArifact( Artifact artifact ); + public abstract String getProjectNameForArifact( Artifact artifact ); /** - * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, but with - * the <code>resolved</code> property set to true. + * Returns the list of project artifacts. Also artifacts generated from referenced projects will be added, + * but with the <code>resolved</code> property set to true. * * @return list of projects artifacts * @throws MojoExecutionException if unable to parse dependency versions @@ -685,46 +702,52 @@ public abstract class AbstractIdeSupport // [MECLIPSE-388] Don't sort this, the order should be identical to getProject.getDependencies() Set artifacts = new LinkedHashSet(); - for (Object o : getProject().getDependencies()) { + for ( Object o : getProject().getDependencies() ) + { Dependency dependency = (Dependency) o; String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); VersionRange versionRange; - try { - versionRange = VersionRange.createFromVersionSpec(dependency.getVersion()); - } catch (InvalidVersionSpecificationException e) { + try + { + versionRange = VersionRange.createFromVersionSpec( dependency.getVersion() ); + } + catch ( InvalidVersionSpecificationException e ) + { throw new MojoExecutionException( - Messages.getString( - "AbstractIdeSupportMojo.unabletoparseversion", new Object[]{ //$NON-NLS-1$ - dependency.getArtifactId(), - dependency.getVersion(), - dependency.getManagementKey(), e.getMessage()}), - e); + Messages.getString( "AbstractIdeSupportMojo.unabletoparseversion", + new Object[] { dependency.getArtifactId(), + dependency.getVersion(), + dependency.getManagementKey(), e.getMessage() } ), + e ); } String type = dependency.getType(); - if (type == null) { + if ( type == null ) + { type = Constants.PROJECT_PACKAGING_JAR; } String classifier = dependency.getClassifier(); boolean optional = dependency.isOptional(); String scope = dependency.getScope(); - if (scope == null) { + if ( scope == null ) + { scope = Artifact.SCOPE_COMPILE; } Artifact art = - getArtifactFactory().createDependencyArtifact(groupId, artifactId, versionRange, type, classifier, - scope, optional); + getArtifactFactory().createDependencyArtifact( groupId, artifactId, versionRange, type, classifier, + scope, optional ); - if (scope.equalsIgnoreCase(Artifact.SCOPE_SYSTEM)) { - art.setFile(new File(dependency.getSystemPath())); + if ( scope.equalsIgnoreCase( Artifact.SCOPE_SYSTEM ) ) + { + art.setFile( new File( dependency.getSystemPath() ) ); } - handleExclusions(art, dependency); + handleExclusions( art, dependency ); - artifacts.add(art); + artifacts.add( art ); } return artifacts; @@ -740,8 +763,9 @@ public abstract class AbstractIdeSupport { List exclusions = new ArrayList(); - for (Exclusion e : dependency.getExclusions()) { - exclusions.add(e.getGroupId() + ":" + e.getArtifactId()); //$NON-NLS-1$ + for ( Exclusion e : dependency.getExclusions() ) + { + exclusions.add( e.getGroupId() + ":" + e.getArtifactId() ); } ArtifactFilter newFilter = new ExcludesArtifactFilter( exclusions ); @@ -770,19 +794,24 @@ public abstract class AbstractIdeSupport { if ( reactorProjects != null ) { - for (Object reactorProject1 : reactorProjects) { + for ( Object reactorProject1 : reactorProjects ) + { MavenProject reactorProject = (MavenProject) reactorProject1; - if (reactorProject.getGroupId().equals(artifact.getGroupId()) - && reactorProject.getArtifactId().equals(artifact.getArtifactId())) { - if (reactorProject.getVersion().equals(artifact.getVersion())) { + if ( reactorProject.getGroupId().equals( artifact.getGroupId() ) + && reactorProject.getArtifactId().equals( artifact.getArtifactId() ) ) + { + if ( reactorProject.getVersion().equals( artifact.getVersion() ) ) + { return reactorProject; - } else { - getLog().info( - "Artifact " - + artifact.getId() - + " already available as a reactor project, but with different version. Expected: " - + artifact.getVersion() + ", found: " + reactorProject.getVersion()); + } + else + { + getLog().info( "Artifact " + + artifact.getId() + + " already available as a reactor project, but with different version. " + + "Expected: " + artifact.getVersion() + ", found: " + + reactorProject.getVersion() ); } } } @@ -806,23 +835,26 @@ public abstract class AbstractIdeSupport if ( dependencyManagement != null && dependencyManagement.getDependencies() != null ) { map = new HashMap(); - for (Dependency d : dependencyManagement.getDependencies()) { - try { - VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); + for ( Dependency d : dependencyManagement.getDependencies() ) + { + try + { + VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); Artifact artifact = - artifactFactory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, - d.getType(), d.getClassifier(), d.getScope(), - d.isOptional()); - - handleExclusions(artifact, d); - map.put(d.getManagementKey(), artifact); - } catch (InvalidVersionSpecificationException e) { + artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, + d.getType(), d.getClassifier(), d.getScope(), + d.isOptional() ); + + handleExclusions( artifact, d ); + map.put( d.getManagementKey(), artifact ); + } + catch ( InvalidVersionSpecificationException e ) + { throw new MojoExecutionException( - Messages.getString( - "AbstractIdeSupportMojo.unabletoparseversion", new Object[]{ //$NON-NLS-1$ - projectId, d.getVersion(), - d.getManagementKey(), e.getMessage()}), - e); + Messages.getString( "AbstractIdeSupportMojo.unabletoparseversion", + new Object[] { projectId, d.getVersion(), + d.getManagementKey(), e.getMessage() } ), + e ); } } } @@ -868,70 +900,84 @@ public abstract class AbstractIdeSupport // local repository for reporting missing source jars List remoteRepos = includeRemoteRepositories ? getRemoteArtifactRepositories() : Collections.EMPTY_LIST; - for (IdeDependency dependency : deps) { - if (dependency.isReferencedProject() || dependency.isSystemScoped()) { + for ( IdeDependency dependency : deps ) + { + if ( dependency.isReferencedProject() || dependency.isSystemScoped() ) + { // artifact not needed continue; } - if (getLog().isDebugEnabled()) { - getLog().debug( - "Searching for sources for " + dependency.getId() + ":" + dependency.getClassifier() - + " at " + dependency.getId() + ":" + inClassifier); + if ( getLog().isDebugEnabled() ) + { + getLog().debug( "Searching for sources for " + dependency.getId() + ":" + dependency.getClassifier() + + " at " + dependency.getId() + ":" + inClassifier ); } Artifact baseArtifact = - artifactFactory.createArtifactWithClassifier(dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), dependency.getType(), - dependency.getClassifier()); + artifactFactory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), + dependency.getVersion(), dependency.getType(), + dependency.getClassifier() ); baseArtifact = - IdeUtils.resolveArtifact(artifactResolver, baseArtifact, remoteRepos, localRepository, getLog()); - if (!baseArtifact.isResolved()) { + IdeUtils.resolveArtifact( artifactResolver, baseArtifact, remoteRepos, localRepository, getLog() ); + if ( !baseArtifact.isResolved() ) + { // base artifact does not exist - no point checking for javadoc/sources continue; } Artifact artifact = - IdeUtils.createArtifactWithClassifier(dependency.getGroupId(), dependency.getArtifactId(), - dependency.getVersion(), dependency.getClassifier(), - inClassifier, artifactFactory); - File notAvailableMarkerFile = IdeUtils.getNotAvailableMarkerFile(localRepository, artifact); - - if (forceRecheck && notAvailableMarkerFile.exists()) { - if (!notAvailableMarkerFile.delete()) { - getLog().warn( - Messages.getString("AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile", - notAvailableMarkerFile)); + IdeUtils.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(), + dependency.getVersion(), dependency.getClassifier(), + inClassifier, artifactFactory ); + File notAvailableMarkerFile = IdeUtils.getNotAvailableMarkerFile( localRepository, artifact ); + + if ( forceRecheck && notAvailableMarkerFile.exists() ) + { + if ( !notAvailableMarkerFile.delete() ) + { + getLog().warn( Messages.getString( "AbstractIdeSupportMojo.unabletodeletenotavailablemarkerfile", + notAvailableMarkerFile ) ); } } - if (!notAvailableMarkerFile.exists()) { + if ( !notAvailableMarkerFile.exists() ) + { artifact = - IdeUtils.resolveArtifact(artifactResolver, artifact, remoteRepos, localRepository, getLog()); - if (artifact.isResolved()) { - if ("sources".equals(inClassifier)) { - dependency.setSourceAttachment(artifact.getFile()); - } else if ("javadoc".equals(inClassifier) && includeRemoteRepositories ) { - dependency.setJavadocAttachment(artifact.getFile()); + IdeUtils.resolveArtifact( artifactResolver, artifact, remoteRepos, localRepository, getLog() ); + if ( artifact.isResolved() ) + { + if ( "sources".equals( inClassifier ) ) + { + dependency.setSourceAttachment( artifact.getFile() ); + } + else if ( "javadoc".equals( inClassifier ) && includeRemoteRepositories ) + { + dependency.setJavadocAttachment( artifact.getFile() ); } - } else { - if (includeRemoteRepositories) { - try { + } + else + { + if ( includeRemoteRepositories ) + { + try + { notAvailableMarkerFile.createNewFile(); - getLog().debug( - Messages.getString("AbstractIdeSupportMojo.creatednotavailablemarkerfile", - notAvailableMarkerFile)); - } catch (IOException e) { - getLog().warn( - Messages.getString( - "AbstractIdeSupportMojo.failedtocreatenotavailablemarkerfile", - notAvailableMarkerFile)); + getLog().debug( + Messages.getString( "AbstractIdeSupportMojo.creatednotavailablemarkerfile", + notAvailableMarkerFile ) ); + } + catch ( IOException e ) + { + getLog().warn( + Messages.getString( "AbstractIdeSupportMojo.failedtocreatenotavailablemarkerfile", + notAvailableMarkerFile ) ); } } // add the dependencies to the list // of those lacking the required // artifact - missingClassifierDependencies.add(dependency); + missingClassifierDependencies.add( dependency ); } } } @@ -951,22 +997,24 @@ public abstract class AbstractIdeSupport if ( getDownloadSources() && !missingSourceDependencies.isEmpty() ) { - msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotavailable" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesnotavailable" ) ); - for (Object missingSourceDependency : missingSourceDependencies) { + for ( Object missingSourceDependency : missingSourceDependencies ) + { IdeDependency art = (IdeDependency) missingSourceDependency; - msg.append(Messages.getString("AbstractIdeSupportMojo.sourcesmissingitem", art.getId())); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.sourcesmissingitem", art.getId() ) ); } msg.append( "\n" ); //$NON-NLS-1$ } if ( getDownloadJavadocs() && !missingJavadocDependencies.isEmpty() ) { - msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotavailable" ) ); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocnotavailable" ) ); - for (Object missingJavadocDependency : missingJavadocDependencies) { + for ( Object missingJavadocDependency : missingJavadocDependencies ) + { IdeDependency art = (IdeDependency) missingJavadocDependency; - msg.append(Messages.getString("AbstractIdeSupportMojo.javadocmissingitem", art.getId())); //$NON-NLS-1$ + msg.append( Messages.getString( "AbstractIdeSupportMojo.javadocmissingitem", art.getId() ) ); } msg.append( "\n" ); //$NON-NLS-1$ }
Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeDependency.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeDependency.java?rev=1705359&r1=1705358&r2=1705359&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeDependency.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeDependency.java Fri Sep 25 21:53:36 2015 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.ide; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,7 +18,6 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.ide; import java.io.File; Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java?rev=1705359&r1=1705358&r2=1705359&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java Fri Sep 25 21:53:36 2015 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.ide; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,7 +18,6 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.ide; import java.io.File; import java.io.IOException; @@ -72,22 +73,22 @@ public class IdeUtils /** * compiler plugin id. */ - private static final String ARTIFACT_MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; //$NON-NLS-1$ + private static final String ARTIFACT_MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; /** * 'source' property for maven-compiler-plugin. */ - private static final String PROPERTY_SOURCE = "source"; //$NON-NLS-1$ + private static final String PROPERTY_SOURCE = "source"; /** * 'encoding' property for maven-compiler-plugin. */ - private static final String PROPERTY_ENCODING = "encoding"; //$NON-NLS-1$ + private static final String PROPERTY_ENCODING = "encoding"; /** * 'target' property for maven-compiler-plugin. */ - private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$ + private static final String PROPERTY_TARGET = "target"; /** * The suffix used to mark a file as not available. @@ -105,11 +106,11 @@ public class IdeUtils { if ( f.isDirectory() ) { - log.info( Messages.getString( "EclipseCleanMojo.deletingDirectory", f.getName() ) ); //$NON-NLS-1$ + log.info( Messages.getString( "EclipseCleanMojo.deletingDirectory", f.getName() ) ); } else { - log.info( Messages.getString( "EclipseCleanMojo.deletingFile", f.getName() ) ); //$NON-NLS-1$ + log.info( Messages.getString( "EclipseCleanMojo.deletingFile", f.getName() ) ); } if ( f.exists() ) @@ -122,7 +123,7 @@ public class IdeUtils } catch ( IOException e ) { - throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.failedtodelete", //$NON-NLS-1$ + throw new MojoExecutionException( Messages.getString( "EclipseCleanMojo.failedtodelete", new Object[] { f.getName(), f.getAbsolutePath() } ) ); } @@ -130,7 +131,7 @@ public class IdeUtils } else { - log.debug( Messages.getString( "EclipseCleanMojo.nofilefound", f.getName() ) ); //$NON-NLS-1$ + log.debug( Messages.getString( "EclipseCleanMojo.nofilefound", f.getName() ) ); } } @@ -143,7 +144,7 @@ public class IdeUtils } catch ( IOException e ) { - throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcanonicalize", file //$NON-NLS-1$ + throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcanonicalize", file .getAbsolutePath() ), e ); } } @@ -188,11 +189,11 @@ public class IdeUtils public static String getCompilerSourceEncoding( MavenProject project ) { String value = IdeUtils.getCompilerPluginSetting( project, PROPERTY_ENCODING ); - if ( value == null ) + if ( value == null ) { project.getProperties().getProperty( "project.build.sourceEncoding" ); } - return value; + return value; } /** @@ -237,9 +238,9 @@ public class IdeUtils * <p> * The {@code len} parameter indicated what to to return: * <ul> - * <li><strong>1</strong> indicated <code>major</code> version</li> - * <li><strong>3</strong> indicated <code>major dot minor</code> version</li> - * <li><strong>5 and above</strong> indicates <code>major dot minor dot incremental</code> version + * <li><strong>1</strong> indicated <code>major</code> version</li> + * <li><strong>3</strong> indicated <code>major dot minor</code> version</li> + * <li><strong>5 and above</strong> indicates <code>major dot minor dot incremental</code> version * </ul> * * @param artifactIds artifact names to compare against for extracting version @@ -254,23 +255,23 @@ public class IdeUtils if ( artifactVersion != null ) { StringBuilder versionBuffer = new StringBuilder(); - if( len >= 1 ) + if ( len >= 1 ) { versionBuffer.append( artifactVersion.getMajorVersion() ); } - if( len >= 2 ) + if ( len >= 2 ) { versionBuffer.append( '.' ); - } - if( len >= 3 ) + } + if ( len >= 3 ) { versionBuffer.append( artifactVersion.getMinorVersion() ); } - if( len >= 4 ) + if ( len >= 4 ) { versionBuffer.append( '.' ); - } - if( len >= 5 ) + } + if ( len >= 5 ) { versionBuffer.append( artifactVersion.getIncrementalVersion() ); } @@ -278,20 +279,22 @@ public class IdeUtils } return version; } - + /** - * * @param artifactIds an array of artifactIds, should not be <code>null</code> * @param dependencies a list of {@link Dependency}-objects, should not be <code>null</code> * @return the resolved ArtifactVersion, otherwise <code>null</code> */ - public static ArtifactVersion getArtifactVersion( String[] artifactIds, List /*<Dependency>*/ dependencies ) + public static ArtifactVersion getArtifactVersion( String[] artifactIds, List /* <Dependency> */dependencies ) { - for (String id : artifactIds) { - for (Object dependency : dependencies) { + for ( String id : artifactIds ) + { + for ( Object dependency : dependencies ) + { Dependency dep = (Dependency) dependency; - if (id.equals(dep.getArtifactId())) { - return VersionRange.createFromVersion(dep.getVersion()).getRecommendedVersion(); + if ( id.equals( dep.getArtifactId() ) ) + { + return VersionRange.createFromVersion( dep.getVersion() ).getRecommendedVersion(); } } @@ -309,7 +312,8 @@ public class IdeUtils * @param defaultValue the default value if the configuration was not found * @return the value of the option configured in the plugin configuration */ - public static String getPluginSetting( MavenProject project, String pluginId, String optionName, String defaultValue ) + public static String getPluginSetting( MavenProject project, String pluginId, String optionName, + String defaultValue ) { Xpp3Dom dom = getPluginConfigurationDom( project, pluginId ); if ( dom != null && dom.getChild( optionName ) != null ) @@ -359,12 +363,15 @@ public class IdeUtils && index < subConfiguration.length; index++ ) { ArrayList newConfigurationDomList = new ArrayList(); - for (Object aConfigurationDomList : configurationDomList) { + for ( Object aConfigurationDomList : configurationDomList ) + { Xpp3Dom child = (Xpp3Dom) aConfigurationDomList; - Xpp3Dom[] deeperChild = child.getChildren(subConfiguration[index]); - for (Xpp3Dom aDeeperChild : deeperChild) { - if (aDeeperChild != null) { - newConfigurationDomList.add(aDeeperChild); + Xpp3Dom[] deeperChild = child.getChildren( subConfiguration[index] ); + for ( Xpp3Dom aDeeperChild : deeperChild ) + { + if ( aDeeperChild != null ) + { + newConfigurationDomList.add( aDeeperChild ); } } } @@ -490,8 +497,8 @@ public class IdeUtils catch ( ArtifactResolutionException e ) { String message = - Messages.getString( "IdeUtils.errorresolving", new Object[] { artifact.getClassifier(), - artifact.getId(), e.getMessage() } ); + Messages.getString( "IdeUtils.errorresolving", + new Object[] { artifact.getClassifier(), artifact.getId(), e.getMessage() } ); log.warn( message ); } @@ -554,17 +561,17 @@ public class IdeUtils version = IdeUtils.getCompilerSourceVersion( project ); } - if ( "1.5".equals( version ) ) //$NON-NLS-1$ + if ( "1.5".equals( version ) ) { - version = IdeUtils.JAVA_5_0;// see MECLIPSE-47 eclipse only accept 5.0 as a valid version + version = IdeUtils.JAVA_5_0; // see MECLIPSE-47 eclipse only accept 5.0 as a valid version } - else if ( "1.6".equals( version ) ) //$NON-NLS-1$ + else if ( "1.6".equals( version ) ) { version = IdeUtils.JAVA_6_0; } else if ( version != null && version.length() == 1 ) { - version = version + ".0";// 5->5.0 6->6.0 7->7.0 //$NON-NLS-1$ + version = version + ".0"; // 5->5.0 6->6.0 7->7.0 //$NON-NLS-1$ } return version == null ? IdeUtils.JAVA_1_4 : version; @@ -654,29 +661,34 @@ public class IdeUtils { String value = null; - for (Object plugin1 : plugins) { + for ( Object plugin1 : plugins ) + { Plugin plugin = (Plugin) plugin1; - if (plugin.getArtifactId().equals(ARTIFACT_MAVEN_COMPILER_PLUGIN)) { + if ( plugin.getArtifactId().equals( ARTIFACT_MAVEN_COMPILER_PLUGIN ) ) + { // TODO: This may cause ClassCastExceptions eventually, if the dom impls differ. Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration(); // this is the default setting - if (o != null && o.getChild(optionName) != null) { - value = o.getChild(optionName).getValue(); + if ( o != null && o.getChild( optionName ) != null ) + { + value = o.getChild( optionName ).getValue(); } List executions = plugin.getExecutions(); // a different source/target version can be configured for test sources compilation - for (Object execution1 : executions) { + for ( Object execution1 : executions ) + { PluginExecution execution = (PluginExecution) execution1; // TODO: This may cause ClassCastExceptions eventually, if the dom impls differ. o = (Xpp3Dom) execution.getConfiguration(); - if (o != null && o.getChild(optionName) != null) { - value = o.getChild(optionName).getValue(); + if ( o != null && o.getChild( optionName ) != null ) + { + value = o.getChild( optionName ).getValue(); } } } Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java?rev=1705359&r1=1705358&r2=1705359&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeDescriptor.java Fri Sep 25 21:53:36 2015 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.ide; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,8 +18,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.ide; +/** + * + */ public class JeeDescriptor { private String jeeVersion; Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java?rev=1705359&r1=1705358&r2=1705359&view=diff ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java Fri Sep 25 21:53:36 2015 @@ -1,3 +1,5 @@ +package org.apache.maven.plugin.ide; + /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -16,33 +18,35 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.maven.plugin.ide; import java.util.HashMap; import java.util.Map; import org.apache.maven.project.MavenProject; +/** + * + */ public class JeeUtils { public static final String ARTIFACT_MAVEN_EAR_PLUGIN = "org.apache.maven.plugins:maven-ear-plugin"; //$NON-NLS-1$ public static final String ARTIFACT_MAVEN_WAR_PLUGIN = "org.apache.maven.plugins:maven-war-plugin"; //$NON-NLS-1$ - private static final Map ejbMap = new HashMap(); + private static final Map EJB_MAP = new HashMap(); - private static final Map jeeMap = new HashMap(); + private static final Map JEE_MAP = new HashMap(); - private static final Map jspMap = new HashMap(); + private static final Map JSP_MAP = new HashMap(); - private static final Map servletMap = new HashMap(); + private static final Map SERVLET_MAP = new HashMap(); /** Names of artifacts of ejb APIs. */ // private static final String[] EJB_API_ARTIFACTS = new String[] { "ejb", "ejb-api", "geronimo-spec-ejb" }; // //$NON-NLS-1$ static { - addJEE( JeeDescriptor.JEE_6_0, JeeDescriptor.EJB_3_1, JeeDescriptor.SERVLET_3_0, JeeDescriptor.JSP_2_2 ); + addJEE( JeeDescriptor.JEE_6_0, JeeDescriptor.EJB_3_1, JeeDescriptor.SERVLET_3_0, JeeDescriptor.JSP_2_2 ); addJEE( JeeDescriptor.JEE_5_0, JeeDescriptor.EJB_3_0, JeeDescriptor.SERVLET_2_5, JeeDescriptor.JSP_2_1 ); addJEE( JeeDescriptor.JEE_1_4, JeeDescriptor.EJB_2_1, JeeDescriptor.SERVLET_2_4, JeeDescriptor.JSP_2_0 ); addJEE( JeeDescriptor.JEE_1_3, JeeDescriptor.EJB_2_0, JeeDescriptor.SERVLET_2_3, JeeDescriptor.JSP_1_2 ); @@ -56,12 +60,16 @@ public class JeeUtils * @param ejbVersion An EJB version as defined by constants JeeDescriptor.EJB_x_x * @return a JEEDescriptor */ - public final static JeeDescriptor getJeeDescriptorFromEjbVersion( String ejbVersion ) + public static final JeeDescriptor getJeeDescriptorFromEjbVersion( String ejbVersion ) { - if ( ejbMap.containsKey( ejbVersion ) ) - return (JeeDescriptor) ejbMap.get( ejbVersion ); + if ( EJB_MAP.containsKey( ejbVersion ) ) + { + return (JeeDescriptor) EJB_MAP.get( ejbVersion ); + } else + { return null; + } } /** @@ -70,12 +78,16 @@ public class JeeUtils * @param jeeVersion A JEE version as defined by constants JeeDescriptor.JEE_x_x * @return a JEEDescriptor */ - public final static JeeDescriptor getJeeDescriptorFromJeeVersion( String jeeVersion ) + public static final JeeDescriptor getJeeDescriptorFromJeeVersion( String jeeVersion ) { - if ( jeeMap.containsKey( jeeVersion ) ) - return (JeeDescriptor) jeeMap.get( jeeVersion ); + if ( JEE_MAP.containsKey( jeeVersion ) ) + { + return (JeeDescriptor) JEE_MAP.get( jeeVersion ); + } else + { return null; + } } /** @@ -84,12 +96,16 @@ public class JeeUtils * @param jspVersion A JSP version as defined by constants JeeDescriptor.JSP_x_x * @return a JEEDescriptor */ - public final static JeeDescriptor getJeeDescriptorFromJspVersion( String jspVersion ) + public static final JeeDescriptor getJeeDescriptorFromJspVersion( String jspVersion ) { - if ( jspMap.containsKey( jspVersion ) ) - return (JeeDescriptor) jspMap.get( jspVersion ); + if ( JSP_MAP.containsKey( jspVersion ) ) + { + return (JeeDescriptor) JSP_MAP.get( jspVersion ); + } else + { return null; + } } /** @@ -98,12 +114,16 @@ public class JeeUtils * @param servletVersion A Servlet version as defined by constants JeeDescriptor.SERVLET_x_x * @return a JEEDescriptor */ - public final static JeeDescriptor getJeeDescriptorFromServletVersion( String servletVersion ) + public static final JeeDescriptor getJeeDescriptorFromServletVersion( String servletVersion ) { - if ( servletMap.containsKey( servletVersion ) ) - return (JeeDescriptor) servletMap.get( servletVersion ); + if ( SERVLET_MAP.containsKey( servletVersion ) ) + { + return (JeeDescriptor) SERVLET_MAP.get( servletVersion ); + } else + { return null; + } } /** @@ -123,7 +143,9 @@ public class JeeUtils // version from J2EE/JEE. JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getEjbVersion(); + } } return version == null ? JeeDescriptor.EJB_2_1 : version; //$NON-NLS-1$ } @@ -145,15 +167,20 @@ public class JeeUtils // version from EJB. JeeDescriptor descriptor = getJeeDescriptorFromEjbVersion( findEjbVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getJeeVersion(); + } } if ( version == null ) { // No JEE dependency detected. Try to resolve the JEE // version from SERVLET. - JeeDescriptor descriptor = getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) ); + JeeDescriptor descriptor = + getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getJeeVersion(); + } } if ( version == null ) { @@ -161,9 +188,11 @@ public class JeeUtils // version from JSP. JeeDescriptor descriptor = getJeeDescriptorFromJspVersion( findJspVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getJeeVersion(); + } } - return version == null ? JeeDescriptor.JEE_1_4 : version; //$NON-NLS-1$ + return version == null ? JeeDescriptor.JEE_1_4 : version; } /** @@ -184,15 +213,20 @@ public class JeeUtils // version from J2EE/JEE. JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getJspVersion(); + } } if ( version == null ) { // No jsp dependency detected. Try to resolve the jsp // version from Servlet. - JeeDescriptor descriptor = getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) ); + JeeDescriptor descriptor = + getJeeDescriptorFromServletVersion( findServletVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getJspVersion(); + } } return version == null ? JeeDescriptor.JSP_2_0 : version; //$NON-NLS-1$ } @@ -214,7 +248,9 @@ public class JeeUtils // version from J2EE/JEE. JeeDescriptor descriptor = getJeeDescriptorFromJeeVersion( findJeeVersionInDependencies( project ) ); if ( descriptor != null ) + { version = descriptor.getServletVersion(); + } } return version == null ? JeeDescriptor.SERVLET_2_4 : version; //$NON-NLS-1$ } @@ -222,10 +258,10 @@ public class JeeUtils private static void addJEE( String jeeVersion, String ejbVersion, String servletVersion, String jspVersion ) { JeeDescriptor descriptor = new JeeDescriptor( jeeVersion, ejbVersion, servletVersion, jspVersion ); - jeeMap.put( jeeVersion, descriptor ); - ejbMap.put( ejbVersion, descriptor ); - servletMap.put( servletVersion, descriptor ); - jspMap.put( jspVersion, descriptor ); + JEE_MAP.put( jeeVersion, descriptor ); + EJB_MAP.put( ejbVersion, descriptor ); + SERVLET_MAP.put( servletVersion, descriptor ); + JSP_MAP.put( jspVersion, descriptor ); } private static String findEjbVersionInDependencies( MavenProject project ) @@ -235,24 +271,27 @@ public class JeeUtils IdeUtils.getArtifactVersion( new String[] { "ejb", "ejb-api", "geronimo-spec-ejb" }, project.getDependencies(), 3 ); // For new Geronimo APIs, the version of the artifact isn't the one of the spec - if ( version == null ) + if ( version == null + && IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_2.1_spec" }, + project.getDependencies(), 3 ) != null ) { - if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_2.1_spec" }, project.getDependencies(), 3 ) != null ) - return JeeDescriptor.EJB_2_1; + return JeeDescriptor.EJB_2_1; } - if ( version == null ) + if ( version == null + && IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_3.0_spec" }, + project.getDependencies(), 3 ) != null ) { - if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-ejb_3.0_spec" }, project.getDependencies(), 3 ) != null ) - return JeeDescriptor.EJB_3_0; + return JeeDescriptor.EJB_3_0; } // if no version found try dependencies of referenced projects if ( version == null ) { - for (Object key : project.getProjectReferences().keySet()) { - MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); - version = findEjbVersionInDependencies(refProject); - if (version != null) // version found in dependencies + for ( Object key : project.getProjectReferences().keySet() ) + { + MavenProject refProject = (MavenProject) project.getProjectReferences().get( key ); + version = findEjbVersionInDependencies( refProject ); + if ( version != null ) // version found in dependencies { break; } @@ -268,19 +307,21 @@ public class JeeUtils project.getDependencies(), 3 ); // For new Geronimo APIs, the version of the artifact isn't the one of the spec - if ( version == null ) + if ( version == null + && IdeUtils.getArtifactVersion( new String[] { "geronimo-j2ee_1.4_spec" }, + project.getDependencies(), 3 ) != null ) { - if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-j2ee_1.4_spec" }, project.getDependencies(), 3 ) != null ) - return JeeDescriptor.JEE_1_4; + return JeeDescriptor.JEE_1_4; } // if no version found try dependencies of referenced projects if ( version == null ) { - for (Object key : project.getProjectReferences().keySet()) { - MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); - version = findJeeVersionInDependencies(refProject); - if (version != null) // version found in dependencies + for ( Object key : project.getProjectReferences().keySet() ) + { + MavenProject refProject = (MavenProject) project.getProjectReferences().get( key ); + version = findJeeVersionInDependencies( refProject ); + if ( version != null ) // version found in dependencies { break; } @@ -302,26 +343,28 @@ public class JeeUtils project.getDependencies(), 3 ); // For new Geronimo APIs, the version of the artifact isn't the one of the spec - if ( version == null ) + if ( version == null + && IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.4_spec" }, + project.getDependencies(), 3 ) != null ) { - if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.4_spec" }, project.getDependencies(), - 3 ) != null ) return JeeDescriptor.SERVLET_2_4; } - if ( version == null ) + + if ( version == null + && IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.5_spec" }, + project.getDependencies(), 3 ) != null ) { - if ( IdeUtils.getArtifactVersion( new String[] { "geronimo-servlet_2.5_spec" }, project.getDependencies(), - 3 ) != null ) return JeeDescriptor.SERVLET_2_5; } // if no version found try dependencies of referenced projects if ( version == null ) { - for (Object key : project.getProjectReferences().keySet()) { - MavenProject refProject = (MavenProject) project.getProjectReferences().get(key); - version = findServletVersionInDependencies(refProject); - if (version != null) // version found in dependencies + for ( Object key : project.getProjectReferences().keySet() ) + { + MavenProject refProject = (MavenProject) project.getProjectReferences().get( key ); + version = findServletVersionInDependencies( refProject ); + if ( version != null ) // version found in dependencies { break; }
