From 369cde893e40e41a37608511addf6f38524314c3 Mon Sep 17 00:00:00 2001 From: sseifert Date: Tue, 16 Feb 2016 22:31:00 +0100 Subject: [PATCH] newlines --- .../WorkspaceDependencyResolveMojo.java | 402 ++++++------- .../plugin/eclipse/LinkedResourceTest.java | 120 ++-- .../eclipse/WorkspaceConfigurationTest.java | 114 ++-- .../plugin/eclipse/it/SelectorUtils.java | 568 +++++++++--------- .../multymodule-1/expected/.project | 48 +- .../multymodule-2/expected/.project | 50 +- .../multymodule-3/expected/.project | 38 +- .../multymodule-4/expected/.project | 44 +- 8 files changed, 692 insertions(+), 692 deletions(-) diff --git a/src/main/java/org/apache/maven/plugin/eclipse/WorkspaceDependencyResolveMojo.java b/src/main/java/org/apache/maven/plugin/eclipse/WorkspaceDependencyResolveMojo.java index d22d410e..7ed39ac2 100644 --- a/src/main/java/org/apache/maven/plugin/eclipse/WorkspaceDependencyResolveMojo.java +++ b/src/main/java/org/apache/maven/plugin/eclipse/WorkspaceDependencyResolveMojo.java @@ -1,201 +1,201 @@ -package org.apache.maven.plugin.eclipse; - -/* - * 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 java.io.File; -import java.io.FileReader; -import java.util.ArrayList; -import java.util.List; - -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; -import org.apache.maven.artifact.resolver.ArtifactResolver; -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugin.eclipse.reader.ReadWorkspaceLocations; -import org.apache.maven.plugins.annotations.Component; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; - -/** - * For all projects currently part of the workspace, all references to the M2_REPO classpath variable are - * resolved. - *

- * Note: not the projects of the reactor are inspected for unresolved artifacts, but the projects that are part - * of the workspace. - * - * @since 2.10 - * @author agudian - */ -@Mojo( name = "resolve-workspace-dependencies", aggregator = true, requiresProject = false ) -public class WorkspaceDependencyResolveMojo - extends AbstractMojo -{ - /** - * The eclipse workspace directory. - *

- * If omitted, the parent directories of the working directory are checked. The first directory to contain a - * .metadata subdirectory is chosen. - */ - @Parameter( property = "eclipse.workspace" ) - private File workspace; - - @Component( role = ArtifactFactory.class ) - private ArtifactFactory artifactFactory; - - @Component( role = ArtifactResolver.class ) - private ArtifactResolver artifactResolver; - - @Parameter( property = "project.remoteArtifactRepositories", required = true, readonly = true ) - private List remoteArtifactRepositories; - - @Parameter( property = "localRepository", required = true, readonly = true ) - private ArtifactRepository localRepository; - - private List findProjectLocations( File workspaceLocation ) - { - return new ReadWorkspaceLocations().readProjectLocations( workspaceLocation, getLog() ); - } - - private void validateWorkspaceLocation() - throws MojoExecutionException - { - if ( workspace != null && !isWorkspaceDirectory( workspace ) ) - { - throw new MojoExecutionException( "Not a workspace directory: there is no subdirectory .metadata at " - + workspace ); - } - - if ( workspace == null ) - { - File currentWorkingDirectory = new File( "." ).getAbsoluteFile(); - while ( currentWorkingDirectory != null ) - { - if ( isWorkspaceDirectory( currentWorkingDirectory ) ) - { - getLog().debug( "Detected workspace at " + currentWorkingDirectory ); - workspace = currentWorkingDirectory; - return; - } - currentWorkingDirectory = currentWorkingDirectory.getParentFile(); - } - } - - throw new MojoExecutionException( "No workspace location configured " - + "and none can be detected in the parent directories." ); - } - - private boolean isWorkspaceDirectory( File currentWorkingDirectory ) - { - return new File( currentWorkingDirectory, ".metadata" ).isDirectory(); - } - - public void execute() - throws MojoExecutionException, MojoFailureException - { - validateWorkspaceLocation(); - - for ( File location : findProjectLocations( workspace ) ) - { - File classpathFile = new File( location, ".classpath" ); - if ( classpathFile.exists() ) - { - getLog().info( "Resolving M2_REPO dependencies in " + classpathFile ); - try - { - Xpp3Dom classpath = Xpp3DomBuilder.build( new FileReader( classpathFile ) ); - - for ( Xpp3Dom entry : classpath.getChildren() ) - { - if ( "var".equals( entry.getAttribute( "kind" ) ) ) - { - resolveIfNecessary( entry.getAttribute( "path" ) ); - resolveIfNecessary( entry.getAttribute( "sourcepath" ) ); - } - } - - } - catch ( Exception e ) - { - getLog().error( "Error parsing " + classpathFile, e ); - } - - } - } - } - - private void resolveIfNecessary( String path ) - throws ArtifactResolutionException - { - if ( null != path && path.startsWith( "M2_REPO" ) ) - { - try - { - Artifact artifact = createArtifactFromPath( path ); - if ( artifact != null ) - { - artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository ); - } - } - catch ( ArtifactNotFoundException e ) - { - getLog().info( e ); - } - } - } - - private Artifact createArtifactFromPath( String path ) - { - String[] elements = path.split( "/" ); - if ( elements.length < 4 ) - { - getLog().error( "Unexpected repository path structure: " + path ); - return null; - } - - List groupParts = new ArrayList(); - for ( int i = 1; i < elements.length - 3; i++ ) - { - groupParts.add( elements[i] ); - } - String group = StringUtils.join( groupParts.iterator(), "." ); - String artifactId = elements[elements.length - 3]; - String version = elements[elements.length - 2]; - - String classifier = null; - String fileName = elements[elements.length - 1]; - String type = fileName.substring( fileName.lastIndexOf( '.' ) + 1 ); - String possibleClassifier = - fileName.substring( artifactId.length() + version.length() + 1, fileName.length() - type.length() - 1 ); - if ( possibleClassifier.length() > 1 ) - { - classifier = possibleClassifier.substring( 1 ); - } - - return artifactFactory.createArtifactWithClassifier( group, artifactId, version, type, classifier ); - } -} +package org.apache.maven.plugin.eclipse; + +/* + * 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 java.io.File; +import java.io.FileReader; +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.eclipse.reader.ReadWorkspaceLocations; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; + +/** + * For all projects currently part of the workspace, all references to the M2_REPO classpath variable are + * resolved. + *

+ * Note: not the projects of the reactor are inspected for unresolved artifacts, but the projects that are part + * of the workspace. + * + * @since 2.10 + * @author agudian + */ +@Mojo( name = "resolve-workspace-dependencies", aggregator = true, requiresProject = false ) +public class WorkspaceDependencyResolveMojo + extends AbstractMojo +{ + /** + * The eclipse workspace directory. + *

+ * If omitted, the parent directories of the working directory are checked. The first directory to contain a + * .metadata subdirectory is chosen. + */ + @Parameter( property = "eclipse.workspace" ) + private File workspace; + + @Component( role = ArtifactFactory.class ) + private ArtifactFactory artifactFactory; + + @Component( role = ArtifactResolver.class ) + private ArtifactResolver artifactResolver; + + @Parameter( property = "project.remoteArtifactRepositories", required = true, readonly = true ) + private List remoteArtifactRepositories; + + @Parameter( property = "localRepository", required = true, readonly = true ) + private ArtifactRepository localRepository; + + private List findProjectLocations( File workspaceLocation ) + { + return new ReadWorkspaceLocations().readProjectLocations( workspaceLocation, getLog() ); + } + + private void validateWorkspaceLocation() + throws MojoExecutionException + { + if ( workspace != null && !isWorkspaceDirectory( workspace ) ) + { + throw new MojoExecutionException( "Not a workspace directory: there is no subdirectory .metadata at " + + workspace ); + } + + if ( workspace == null ) + { + File currentWorkingDirectory = new File( "." ).getAbsoluteFile(); + while ( currentWorkingDirectory != null ) + { + if ( isWorkspaceDirectory( currentWorkingDirectory ) ) + { + getLog().debug( "Detected workspace at " + currentWorkingDirectory ); + workspace = currentWorkingDirectory; + return; + } + currentWorkingDirectory = currentWorkingDirectory.getParentFile(); + } + } + + throw new MojoExecutionException( "No workspace location configured " + + "and none can be detected in the parent directories." ); + } + + private boolean isWorkspaceDirectory( File currentWorkingDirectory ) + { + return new File( currentWorkingDirectory, ".metadata" ).isDirectory(); + } + + public void execute() + throws MojoExecutionException, MojoFailureException + { + validateWorkspaceLocation(); + + for ( File location : findProjectLocations( workspace ) ) + { + File classpathFile = new File( location, ".classpath" ); + if ( classpathFile.exists() ) + { + getLog().info( "Resolving M2_REPO dependencies in " + classpathFile ); + try + { + Xpp3Dom classpath = Xpp3DomBuilder.build( new FileReader( classpathFile ) ); + + for ( Xpp3Dom entry : classpath.getChildren() ) + { + if ( "var".equals( entry.getAttribute( "kind" ) ) ) + { + resolveIfNecessary( entry.getAttribute( "path" ) ); + resolveIfNecessary( entry.getAttribute( "sourcepath" ) ); + } + } + + } + catch ( Exception e ) + { + getLog().error( "Error parsing " + classpathFile, e ); + } + + } + } + } + + private void resolveIfNecessary( String path ) + throws ArtifactResolutionException + { + if ( null != path && path.startsWith( "M2_REPO" ) ) + { + try + { + Artifact artifact = createArtifactFromPath( path ); + if ( artifact != null ) + { + artifactResolver.resolve( artifact, remoteArtifactRepositories, localRepository ); + } + } + catch ( ArtifactNotFoundException e ) + { + getLog().info( e ); + } + } + } + + private Artifact createArtifactFromPath( String path ) + { + String[] elements = path.split( "/" ); + if ( elements.length < 4 ) + { + getLog().error( "Unexpected repository path structure: " + path ); + return null; + } + + List groupParts = new ArrayList(); + for ( int i = 1; i < elements.length - 3; i++ ) + { + groupParts.add( elements[i] ); + } + String group = StringUtils.join( groupParts.iterator(), "." ); + String artifactId = elements[elements.length - 3]; + String version = elements[elements.length - 2]; + + String classifier = null; + String fileName = elements[elements.length - 1]; + String type = fileName.substring( fileName.lastIndexOf( '.' ) + 1 ); + String possibleClassifier = + fileName.substring( artifactId.length() + version.length() + 1, fileName.length() - type.length() - 1 ); + if ( possibleClassifier.length() > 1 ) + { + classifier = possibleClassifier.substring( 1 ); + } + + return artifactFactory.createArtifactWithClassifier( group, artifactId, version, type, classifier ); + } +} diff --git a/src/test/java/org/apache/maven/plugin/eclipse/LinkedResourceTest.java b/src/test/java/org/apache/maven/plugin/eclipse/LinkedResourceTest.java index 9c659982..86c22880 100644 --- a/src/test/java/org/apache/maven/plugin/eclipse/LinkedResourceTest.java +++ b/src/test/java/org/apache/maven/plugin/eclipse/LinkedResourceTest.java @@ -1,60 +1,60 @@ -/* - * 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. - */ - -package org.apache.maven.plugin.eclipse; - -import static org.junit.Assert.assertEquals; - -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.junit.Test; - -public class LinkedResourceTest -{ - @Test - public void nodeWithOnlyLocationIsAccepted() - { - Xpp3Dom node = new Xpp3Dom("test"); - node.addChild(new Xpp3Dom("name")); - node.addChild(new Xpp3Dom("type")); - - Xpp3Dom location = new Xpp3Dom("location"); - location.setValue("the-location"); - - node.addChild(location); - - LinkedResource lr = new LinkedResource(node); - assertEquals("the-location", lr.getLocation()); - } - - @Test - public void nodeWithOnlyLocationUriIsAccepted() - { - Xpp3Dom node = new Xpp3Dom("test"); - node.addChild(new Xpp3Dom("name")); - node.addChild(new Xpp3Dom("type")); - - Xpp3Dom location = new Xpp3Dom("locationURI"); - location.setValue("the-location-uri"); - - node.addChild(location); - - LinkedResource lr = new LinkedResource(node); - assertEquals("the-location-uri", lr.getLocationURI()); - } -} +/* + * 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. + */ + +package org.apache.maven.plugin.eclipse; + +import static org.junit.Assert.assertEquals; + +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.Test; + +public class LinkedResourceTest +{ + @Test + public void nodeWithOnlyLocationIsAccepted() + { + Xpp3Dom node = new Xpp3Dom("test"); + node.addChild(new Xpp3Dom("name")); + node.addChild(new Xpp3Dom("type")); + + Xpp3Dom location = new Xpp3Dom("location"); + location.setValue("the-location"); + + node.addChild(location); + + LinkedResource lr = new LinkedResource(node); + assertEquals("the-location", lr.getLocation()); + } + + @Test + public void nodeWithOnlyLocationUriIsAccepted() + { + Xpp3Dom node = new Xpp3Dom("test"); + node.addChild(new Xpp3Dom("name")); + node.addChild(new Xpp3Dom("type")); + + Xpp3Dom location = new Xpp3Dom("locationURI"); + location.setValue("the-location-uri"); + + node.addChild(location); + + LinkedResource lr = new LinkedResource(node); + assertEquals("the-location-uri", lr.getLocationURI()); + } +} diff --git a/src/test/java/org/apache/maven/plugin/eclipse/WorkspaceConfigurationTest.java b/src/test/java/org/apache/maven/plugin/eclipse/WorkspaceConfigurationTest.java index b27f2d7c..991c35c6 100644 --- a/src/test/java/org/apache/maven/plugin/eclipse/WorkspaceConfigurationTest.java +++ b/src/test/java/org/apache/maven/plugin/eclipse/WorkspaceConfigurationTest.java @@ -1,57 +1,57 @@ -package org.apache.maven.plugin.eclipse; - -/* - * 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 junit.framework.TestCase; - -public class WorkspaceConfigurationTest - extends TestCase -{ - - public void testGetWebsphereVersion() - { - WorkspaceConfiguration wc = new WorkspaceConfiguration(); - // Websphere Application Servers - final String was_express_v51 = "was.express.v51"; - wc.setDefaultDeployServerId( was_express_v51 ); - assertEquals( "5.1", wc.getWebsphereVersion() ); - - final String was_base_v51 = "was.base.v51"; - wc.setDefaultDeployServerId( was_base_v51 ); - assertEquals( "5.1", wc.getWebsphereVersion() ); - - final String was_base_v6 = "was.base.v6"; - wc.setDefaultDeployServerId( was_base_v6 ); - assertEquals( "6.0", wc.getWebsphereVersion() ); - - final String was_base_v61 = "was.base.v61"; - wc.setDefaultDeployServerId( was_base_v61 ); - assertEquals( "6.1", wc.getWebsphereVersion() ); - - final String was_base_v7 = "was.base.v7"; - wc.setDefaultDeployServerId( was_base_v7 ); - assertEquals( "7.0", wc.getWebsphereVersion() ); - - // Websphere Portals - //wps.base.v51 - //wps.base.v60 - //wps.base.v61 - } -} +package org.apache.maven.plugin.eclipse; + +/* + * 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 junit.framework.TestCase; + +public class WorkspaceConfigurationTest + extends TestCase +{ + + public void testGetWebsphereVersion() + { + WorkspaceConfiguration wc = new WorkspaceConfiguration(); + // Websphere Application Servers + final String was_express_v51 = "was.express.v51"; + wc.setDefaultDeployServerId( was_express_v51 ); + assertEquals( "5.1", wc.getWebsphereVersion() ); + + final String was_base_v51 = "was.base.v51"; + wc.setDefaultDeployServerId( was_base_v51 ); + assertEquals( "5.1", wc.getWebsphereVersion() ); + + final String was_base_v6 = "was.base.v6"; + wc.setDefaultDeployServerId( was_base_v6 ); + assertEquals( "6.0", wc.getWebsphereVersion() ); + + final String was_base_v61 = "was.base.v61"; + wc.setDefaultDeployServerId( was_base_v61 ); + assertEquals( "6.1", wc.getWebsphereVersion() ); + + final String was_base_v7 = "was.base.v7"; + wc.setDefaultDeployServerId( was_base_v7 ); + assertEquals( "7.0", wc.getWebsphereVersion() ); + + // Websphere Portals + //wps.base.v51 + //wps.base.v60 + //wps.base.v61 + } +} diff --git a/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java b/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java index 40a70d13..36d64ace 100644 --- a/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java +++ b/src/test/java/org/apache/maven/plugin/eclipse/it/SelectorUtils.java @@ -1,284 +1,284 @@ -package org.apache.maven.plugin.eclipse.it; - -/* - * 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 java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.Os; -import org.codehaus.plexus.util.StringUtils; - -/** - * Provides utility methods for selecting build jobs based on environmental conditions. - * - * From org.apache.maven.plugin.invoker.SelectorUtils - * - * @author Benjamin Bentmann - */ -class SelectorUtils -{ - - static void parseList( String list, Collection includes, Collection excludes ) - { - String[] tokens = ( list != null ) ? StringUtils.split( list, "," ) : new String[0]; - - for ( int i = 0; i < tokens.length; i++ ) - { - String token = tokens[i].trim(); - - if ( token.startsWith( "!" ) ) - { - excludes.add( token.substring( 1 ) ); - } - else - { - includes.add( token ); - } - } - } - - static boolean isOsFamily( String osSpec ) - { - List includes = new ArrayList(); - List excludes = new ArrayList(); - parseList( osSpec, includes, excludes ); - - return isOsFamily( includes, true ) && !isOsFamily( excludes, false ); - } - - static boolean isOsFamily( List families, boolean defaultMatch ) - { - if ( families != null && !families.isEmpty() ) - { - for ( String family : families ) - { - if ( Os.isFamily( family ) ) - { - return true; - } - } - - return false; - } - else - { - return defaultMatch; - } - } - - /** - * Retrieves the current Maven version. - * @return The current Maven version. - */ - static String getMavenVersion() - { - try - { - // This relies on the fact that MavenProject is the in core classloader - // and that the core classloader is for the maven-core artifact - // and that should have a pom.properties file - // if this ever changes, we will have to revisit this code. - Properties properties = new Properties(); - properties.load( MavenProject.class.getClassLoader().getResourceAsStream( - "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) ); - return StringUtils.trim( properties.getProperty( "version" ) ); - } - catch ( Exception e ) - { - return null; - } - } - - static String getMavenVersion( File mavenHome ) - { - File mavenLib = new File( mavenHome, "lib" ); - File[] jarFiles = mavenLib.listFiles( new FilenameFilter() - { - public boolean accept( File dir, String name ) - { - return name.endsWith( ".jar" ); - } - } ); - - for ( File file : jarFiles ) - { - try - { - @SuppressWarnings( "deprecation" ) - URL url = - new URL( "jar:" + file.toURL().toExternalForm() - + "!/META-INF/maven/org.apache.maven/maven-core/pom.properties" ); - - Properties properties = new Properties(); - properties.load( url.openStream() ); - String version = StringUtils.trim( properties.getProperty( "version" ) ); - if ( version != null ) - { - return version; - } - } - catch ( MalformedURLException e ) - { - // ignore - } - catch ( IOException e ) - { - // ignore - } - } - return null; - } - - static boolean isMavenVersion( String mavenSpec ) - { - return isMavenVersion( mavenSpec, getMavenVersion() ); - } - - static boolean isMavenVersion( String mavenSpec, String actualVersion ) - { - List includes = new ArrayList(); - List excludes = new ArrayList(); - parseList( mavenSpec, includes, excludes ); - - List mavenVersionList = parseVersion( actualVersion ); - - return isJreVersion( mavenVersionList, includes, true ) && !isJreVersion( mavenVersionList, excludes, false ); - } - - static String getJreVersion() - { - return System.getProperty( "java.version", "" ); - } - - static String getJreVersion( File javaHome ) - { - //@todo detect actual version - return null; - } - - static boolean isJreVersion( String jreSpec ) - { - return isJreVersion( jreSpec, getJreVersion() ); - } - - static boolean isJreVersion( String jreSpec, String actualJreVersion ) - { - List includes = new ArrayList(); - List excludes = new ArrayList(); - parseList( jreSpec, includes, excludes ); - - List jreVersion = parseVersion( actualJreVersion ); - - return isJreVersion( jreVersion, includes, true ) && !isJreVersion( jreVersion, excludes, false ); - } - - - static boolean isJreVersion( List jreVersion, List versionPatterns, boolean defaultMatch ) - { - if ( versionPatterns != null && !versionPatterns.isEmpty() ) - { - for ( String versionPattern : versionPatterns ) - { - if ( isJreVersion( jreVersion, versionPattern ) ) - { - return true; - } - } - - return false; - } - else - { - return defaultMatch; - } - } - - static boolean isJreVersion( List jreVersion, String versionPattern ) - { - List checkVersion = parseVersion( versionPattern ); - - if ( versionPattern.endsWith( "+" ) ) - { - // 1.5+ <=> [1.5,) - return compareVersions( jreVersion, checkVersion ) >= 0; - } - else if ( versionPattern.endsWith( "-" ) ) - { - // 1.5- <=> (,1.5) - return compareVersions( jreVersion, checkVersion ) < 0; - } - else - { - // 1.5 <=> [1.5,1.6) - return checkVersion.size() <= jreVersion.size() && checkVersion.equals( - jreVersion.subList( 0, checkVersion.size() ) ); - } - } - - static List parseVersion( String version ) - { - version = version.replaceAll( "[^0-9]", "." ); - - String[] tokens = StringUtils.split( version, "." ); - - List numbers = new ArrayList(); - - for ( int i = 0; i < tokens.length; i++ ) - { - numbers.add( Integer.valueOf( tokens[i] ) ); - } - - return numbers; - } - - static int compareVersions( List version1, List version2 ) - { - for ( Iterator it1 = version1.iterator(), it2 = version2.iterator(); ; ) - { - if ( !it1.hasNext() ) - { - return it2.hasNext() ? -1 : 0; - } - if ( !it2.hasNext() ) - { - return it1.hasNext() ? 1 : 0; - } - - Integer num1 = it1.next(); - Integer num2 = it2.next(); - - int rel = num1.compareTo( num2 ); - if ( rel != 0 ) - { - return rel; - } - } - } - -} +package org.apache.maven.plugin.eclipse.it; + +/* + * 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 java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.Os; +import org.codehaus.plexus.util.StringUtils; + +/** + * Provides utility methods for selecting build jobs based on environmental conditions. + * + * From org.apache.maven.plugin.invoker.SelectorUtils + * + * @author Benjamin Bentmann + */ +class SelectorUtils +{ + + static void parseList( String list, Collection includes, Collection excludes ) + { + String[] tokens = ( list != null ) ? StringUtils.split( list, "," ) : new String[0]; + + for ( int i = 0; i < tokens.length; i++ ) + { + String token = tokens[i].trim(); + + if ( token.startsWith( "!" ) ) + { + excludes.add( token.substring( 1 ) ); + } + else + { + includes.add( token ); + } + } + } + + static boolean isOsFamily( String osSpec ) + { + List includes = new ArrayList(); + List excludes = new ArrayList(); + parseList( osSpec, includes, excludes ); + + return isOsFamily( includes, true ) && !isOsFamily( excludes, false ); + } + + static boolean isOsFamily( List families, boolean defaultMatch ) + { + if ( families != null && !families.isEmpty() ) + { + for ( String family : families ) + { + if ( Os.isFamily( family ) ) + { + return true; + } + } + + return false; + } + else + { + return defaultMatch; + } + } + + /** + * Retrieves the current Maven version. + * @return The current Maven version. + */ + static String getMavenVersion() + { + try + { + // This relies on the fact that MavenProject is the in core classloader + // and that the core classloader is for the maven-core artifact + // and that should have a pom.properties file + // if this ever changes, we will have to revisit this code. + Properties properties = new Properties(); + properties.load( MavenProject.class.getClassLoader().getResourceAsStream( + "META-INF/maven/org.apache.maven/maven-core/pom.properties" ) ); + return StringUtils.trim( properties.getProperty( "version" ) ); + } + catch ( Exception e ) + { + return null; + } + } + + static String getMavenVersion( File mavenHome ) + { + File mavenLib = new File( mavenHome, "lib" ); + File[] jarFiles = mavenLib.listFiles( new FilenameFilter() + { + public boolean accept( File dir, String name ) + { + return name.endsWith( ".jar" ); + } + } ); + + for ( File file : jarFiles ) + { + try + { + @SuppressWarnings( "deprecation" ) + URL url = + new URL( "jar:" + file.toURL().toExternalForm() + + "!/META-INF/maven/org.apache.maven/maven-core/pom.properties" ); + + Properties properties = new Properties(); + properties.load( url.openStream() ); + String version = StringUtils.trim( properties.getProperty( "version" ) ); + if ( version != null ) + { + return version; + } + } + catch ( MalformedURLException e ) + { + // ignore + } + catch ( IOException e ) + { + // ignore + } + } + return null; + } + + static boolean isMavenVersion( String mavenSpec ) + { + return isMavenVersion( mavenSpec, getMavenVersion() ); + } + + static boolean isMavenVersion( String mavenSpec, String actualVersion ) + { + List includes = new ArrayList(); + List excludes = new ArrayList(); + parseList( mavenSpec, includes, excludes ); + + List mavenVersionList = parseVersion( actualVersion ); + + return isJreVersion( mavenVersionList, includes, true ) && !isJreVersion( mavenVersionList, excludes, false ); + } + + static String getJreVersion() + { + return System.getProperty( "java.version", "" ); + } + + static String getJreVersion( File javaHome ) + { + //@todo detect actual version + return null; + } + + static boolean isJreVersion( String jreSpec ) + { + return isJreVersion( jreSpec, getJreVersion() ); + } + + static boolean isJreVersion( String jreSpec, String actualJreVersion ) + { + List includes = new ArrayList(); + List excludes = new ArrayList(); + parseList( jreSpec, includes, excludes ); + + List jreVersion = parseVersion( actualJreVersion ); + + return isJreVersion( jreVersion, includes, true ) && !isJreVersion( jreVersion, excludes, false ); + } + + + static boolean isJreVersion( List jreVersion, List versionPatterns, boolean defaultMatch ) + { + if ( versionPatterns != null && !versionPatterns.isEmpty() ) + { + for ( String versionPattern : versionPatterns ) + { + if ( isJreVersion( jreVersion, versionPattern ) ) + { + return true; + } + } + + return false; + } + else + { + return defaultMatch; + } + } + + static boolean isJreVersion( List jreVersion, String versionPattern ) + { + List checkVersion = parseVersion( versionPattern ); + + if ( versionPattern.endsWith( "+" ) ) + { + // 1.5+ <=> [1.5,) + return compareVersions( jreVersion, checkVersion ) >= 0; + } + else if ( versionPattern.endsWith( "-" ) ) + { + // 1.5- <=> (,1.5) + return compareVersions( jreVersion, checkVersion ) < 0; + } + else + { + // 1.5 <=> [1.5,1.6) + return checkVersion.size() <= jreVersion.size() && checkVersion.equals( + jreVersion.subList( 0, checkVersion.size() ) ); + } + } + + static List parseVersion( String version ) + { + version = version.replaceAll( "[^0-9]", "." ); + + String[] tokens = StringUtils.split( version, "." ); + + List numbers = new ArrayList(); + + for ( int i = 0; i < tokens.length; i++ ) + { + numbers.add( Integer.valueOf( tokens[i] ) ); + } + + return numbers; + } + + static int compareVersions( List version1, List version2 ) + { + for ( Iterator it1 = version1.iterator(), it2 = version2.iterator(); ; ) + { + if ( !it1.hasNext() ) + { + return it2.hasNext() ? -1 : 0; + } + if ( !it2.hasNext() ) + { + return it1.hasNext() ? 1 : 0; + } + + Integer num1 = it1.next(); + Integer num2 = it2.next(); + + int rel = num1.compareTo( num2 ); + if ( rel != 0 ) + { + return rel; + } + } + } + +} diff --git a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-1/expected/.project b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-1/expected/.project index 322e97b9..0331cd22 100644 --- a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-1/expected/.project +++ b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-1/expected/.project @@ -1,25 +1,25 @@ - - - prefix-multymodule-1-1.0 - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - multymodule-4-1.0 - - - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.wst.common.project.facet.core.builder - - - org.eclipse.wst.validation.validationbuilder - - - - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - + + + prefix-multymodule-1-1.0 + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + multymodule-4-1.0 + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + \ No newline at end of file diff --git a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-2/expected/.project b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-2/expected/.project index 74cd2080..d0093fb5 100644 --- a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-2/expected/.project +++ b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-2/expected/.project @@ -1,26 +1,26 @@ - - - multymodule-2-1.0 - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - prefix-multymodule-1-1.0 - multymodule-4-1.0 - - - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.wst.common.project.facet.core.builder - - - org.eclipse.wst.validation.validationbuilder - - - - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - + + + multymodule-2-1.0 + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + prefix-multymodule-1-1.0 + multymodule-4-1.0 + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + \ No newline at end of file diff --git a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-3/expected/.project b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-3/expected/.project index ed661e58..a36d193f 100644 --- a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-3/expected/.project +++ b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-3/expected/.project @@ -1,20 +1,20 @@ - - - multymodule-3-1.0 - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - multymodule-2-1.0 - - - - org.eclipse.wst.common.project.facet.core.builder - - - org.eclipse.wst.validation.validationbuilder - - - - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.common.modulecore.ModuleCoreNature - + + + multymodule-3-1.0 + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + multymodule-2-1.0 + + + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.common.modulecore.ModuleCoreNature + \ No newline at end of file diff --git a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-4/expected/.project b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-4/expected/.project index ed613432..be5dedcd 100644 --- a/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-4/expected/.project +++ b/src/test/resources/projects/project-51-MECLIPSE-415/multymodule-4/expected/.project @@ -1,23 +1,23 @@ - - - multymodule-4-1.0 - NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - - - - org.eclipse.jdt.core.javabuilder - - - org.eclipse.wst.common.project.facet.core.builder - - - org.eclipse.wst.validation.validationbuilder - - - - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jem.workbench.JavaEMFNature - + + + multymodule-4-1.0 + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + org.eclipse.jdt.core.javabuilder + + + org.eclipse.wst.common.project.facet.core.builder + + + org.eclipse.wst.validation.validationbuilder + + + + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.jem.workbench.JavaEMFNature + \ No newline at end of file