ARCHETYPE-518
authorpetar.tahchiev <paranoiabla@gmail.com>
Tue, 14 Feb 2017 12:18:25 +0000 (14:18 +0200)
committerpetar.tahchiev <paranoiabla@gmail.com>
Tue, 14 Feb 2017 12:18:25 +0000 (14:18 +0200)
Add a commented test-case for ARCHETYPE-518 to demonstrate when parent is trying to read
system properties we cannot create archetype from project.

archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
archetype-testing/archetype-final/src/test/java/org/apache/maven/archetype/creator/DefaultArchetypeCreatorIT.java
archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/archetype.properties.sample [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom-parent.xml.sample [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom.xml.sample [new file with mode: 0644]
archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/src/main/java/App.java [new file with mode: 0644]

index 828af40..0022341 100644 (file)
@@ -435,6 +435,8 @@ public class FilesetArchetypeCreator
                 ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
                 buildingRequest.setLocalRepository( localRepository );
                 buildingRequest.setRemoteRepositories( project.getRemoteArtifactRepositories() );
+//                buildingRequest.setSystemProperties( System.getProperties() );
+//                buildingRequest.setUserProperties( configurationProperties );
                 
                 MavenProject p = projectBuilder.build( pa, buildingRequest ).getProject();
 
index 06663f3..f6156e1 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.maven.archetype.creator;
 
 import org.apache.maven.archetype.ArchetypeCreationRequest;
 import org.apache.maven.archetype.ArchetypeCreationResult;
+import org.apache.maven.archetype.ArchetypeManager;
 import org.apache.maven.archetype.common.Constants;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
@@ -32,9 +33,12 @@ import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.project.ProjectBuildingResult;
 //import org.apache.maven.project.MavenProjectBuildingResult;
+import org.apache.maven.repository.internal.MavenRepositorySystemSession;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.PropertyUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.junit.Ignore;
+import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -56,7 +60,7 @@ public class DefaultArchetypeCreatorIT
         throws Exception
     {
         System.out.println( ">>>>>> testCreateFilesetArchetype( \"" + project + "\" )" );
-        
+
         ProjectBuilder builder = lookup( ProjectBuilder.class );
 
         File projectFile = getProjectFile( project );
@@ -77,7 +81,11 @@ public class DefaultArchetypeCreatorIT
 
         ProjectBuildingRequest buildingRequest = new DefaultProjectBuildingRequest();
         buildingRequest.setLocalRepository( localRepository );
-        
+        buildingRequest.setSystemProperties(System.getProperties());
+        MavenRepositorySystemSession repositorySession = new MavenRepositorySystemSession();
+        repositorySession.setLocalRepositoryManager( new SimpleLocalRepositoryManager(localRepository.getBasedir() ) );
+        buildingRequest.setRepositorySession(repositorySession);
+
         MavenProject mavenProject = builder.build( projectFile, buildingRequest ).getProject();
 
         FilesetArchetypeCreator instance =
@@ -183,6 +191,18 @@ public class DefaultArchetypeCreatorIT
         assertExists(template1);
     }
 
+//    @Ignore("ARCHETYPE-518")
+//    public void testSystemPropertiesAreIncluded()
+//                    throws Exception
+//    {
+//        String project = "included-system-properties";
+//
+//        createFilesetArchetype( project );
+//
+//        File template1 = getTemplateFile( project, "src/main/java/App.java" );
+//        assertExists(template1);
+//    }
+
     public void testCreateFilesetArchetype1()
         throws Exception
     {
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/archetype.properties.sample b/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/archetype.properties.sample
new file mode 100644 (file)
index 0000000..0b139a1
--- /dev/null
@@ -0,0 +1,25 @@
+# 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.
+
+archetype.groupId=org.codehaus.mojo.archetypes
+archetype.artifactId=maven-archetype-test
+archetype.version=1.0
+archetype.languages=csharp
+groupId=org.apache.maven.archetype.test
+artifactId=test
+version=1.0-SNAPSHOT
+package=archetype
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom-parent.xml.sample b/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom-parent.xml.sample
new file mode 100644 (file)
index 0000000..af18fcc
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.test</groupId>
+    <artifactId>test</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>Maven archetype Test Correctly creates archetype when a system property is required.</name>
+    <packaging>pom</packaging>
+
+    <profiles>
+        <profile>
+           <id>doclint-java8-disable</id>
+           <activation>
+             <jdk>[1.8,)</jdk>
+           </activation>
+           <properties>
+             <javadoc.additional.params>-Xdoclint:none</javadoc.additional.params>
+           </properties>
+         </profile>
+    </profiles>
+</project>
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom.xml.sample b/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/pom.xml.sample
new file mode 100644 (file)
index 0000000..5f694b4
--- /dev/null
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<project
+    xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>com.test</groupId>
+        <artifactId>test</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <relativePath>./pom-parent.xml.sample</relativePath>
+    </parent>
+
+    <groupId>org.apache.maven.archetype.test</groupId>
+    <artifactId>included-system-properties</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <name>Maven archetype Test Correctly creates archetype when a system property is required.</name>
+    <packaging>pom</packaging>
+</project>
diff --git a/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/src/main/java/App.java b/archetype-testing/archetype-final/src/test/resources/projects/included-system-properties/src/main/java/App.java
new file mode 100644 (file)
index 0000000..7753325
--- /dev/null
@@ -0,0 +1,50 @@
+package org.apache.maven.test;
+
+/*
+ * 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.
+ */
+
+/**
+ * Hello world!
+ *
+ */
+public class App
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+        //A   #\{some}
+        //B   #{some}
+        //C   #{some other}
+        //D   \#{some other}
+        //E   #{}
+        //F   {some}
+        //G   ${someOtherProperty}
+        //H   ${someValue}
+        /*
+        A   #\{some}
+        B   #{some}
+        C   #{some other}
+        D   \#{some other}
+        E   #{}
+        F   {some}
+        G   ${someOtherProperty}
+        H   ${someValue}
+         */
+    }
+}