Index: archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/CommandArchetypeTest.java
===================================================================
--- archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/CommandArchetypeTest.java (revision 0)
+++ archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/CommandArchetypeTest.java (revision 0)
@@ -0,0 +1,34 @@
+/*
+ * 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.karaf.archetypes;
+
+import java.util.Properties;
+
+/**
+ *
+ * @author iocanel
+ */
+public class CommandArchetypeTest extends AbstractArchetypeTest {
+
+ public void testCommand() throws Exception {
+ Properties commandArchetypeParameters = new Properties();
+ commandArchetypeParameters.setProperty("scope", "testscope");
+ commandArchetypeParameters.setProperty("command", "testcommand");
+ commandArchetypeParameters.setProperty("description", "testdescription");
+ testKarafArchetype("command-archetype", commandArchetypeParameters);
+ }
+}
Index: archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/AbstractArchetypeTest.java
===================================================================
--- archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/AbstractArchetypeTest.java (revision 0)
+++ archetypes/karaf-archetypes-itests/src/test/java/org/apache/karaf/archetypes/AbstractArchetypeTest.java (revision 0)
@@ -0,0 +1,139 @@
+/*
+ * 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.karaf.archetypes;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Properties;
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.artifact.manager.WagonManager;
+import org.apache.maven.cli.ConsoleDownloadMonitor;
+import org.apache.maven.embedder.MavenEmbedder;
+import org.apache.maven.embedder.MavenEmbedderConsoleLogger;
+import org.apache.maven.embedder.MavenEmbedderLogger;
+import org.apache.maven.embedder.PlexusLoggerAdapter;
+import org.apache.maven.monitor.event.DefaultEventMonitor;
+import org.apache.maven.monitor.event.EventMonitor;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.FileUtils;
+
+public abstract class AbstractArchetypeTest extends TestCase {
+
+ private static final String MAVEN_REPO_LOCAL = "maven.repo.local";
+ private static final File baseDir = new File(System.getProperty("basedir", ".")).getAbsoluteFile();
+ private MavenEmbedder maven;
+ private Properties sysProps = System.getProperties();
+ private String version;
+
+ protected void setUp() throws Exception {
+ maven = new MavenEmbedder();
+ maven.setOffline(false);
+ System.err.println(sysProps.getProperty(MAVEN_REPO_LOCAL));
+ if (StringUtils.isNotEmpty(sysProps.getProperty(MAVEN_REPO_LOCAL))) {
+ maven.setLocalRepositoryDirectory(new File(sysProps.getProperty(MAVEN_REPO_LOCAL)));
+ }
+
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ maven.setClassLoader(classLoader);
+ MavenEmbedderLogger logger = new MavenEmbedderConsoleLogger();
+ maven.setLogger(logger);
+ maven.start();
+
+ Field f = maven.getClass().getDeclaredField("wagonManager");
+ f.setAccessible(true);
+ WagonManager wagon = (WagonManager) f.get(maven);
+ wagon.setOnline(true);
+
+ MavenProject project = maven.readProject(new File(baseDir, "pom.xml"));
+ maven.setInteractiveMode(false);
+ version = project.getVersion();
+ }
+
+ protected void tearDown() throws Exception {
+ maven.stop();
+ maven = null;
+ System.gc();
+ }
+
+ protected void testKarafArchetype(String artifactId) throws Exception {
+ testArchetype("org.apache.karaf.archetypes", "karaf-" + artifactId, version, null);
+ }
+
+ protected void testKarafArchetype(String artifactId, Properties archetypeRequiredParameters) throws Exception {
+ testArchetype("org.apache.karaf.archetypes", "karaf-" + artifactId, version, archetypeRequiredParameters);
+ }
+
+ protected void testArchetype(String groupId, String artifactId, String version, Properties archetypeRequiredParameters) throws Exception {
+ File targetDir = new File(baseDir, "target/archetypes/" + artifactId);
+ FileUtils.deleteDirectory(targetDir);
+ targetDir.mkdirs();
+ EventMonitor eventMonitor = new DefaultEventMonitor(new PlexusLoggerAdapter(
+ new MavenEmbedderConsoleLogger()));
+
+ Properties props = new Properties();
+ props.setProperty("archetypeGroupId", groupId);
+ props.setProperty("archetypeArtifactId", artifactId);
+ props.setProperty("archetypeVersion", version);
+ props.setProperty("interactiveMode", "false");
+ props.setProperty("groupId", "sample");
+ props.setProperty("artifactId", UUID.randomUUID().toString());
+ props.setProperty("user.dir", targetDir.getAbsolutePath());
+ props.setProperty("basedir", targetDir.getAbsolutePath());
+
+ //Some archetypes require additional parameters
+ if (archetypeRequiredParameters != null) {
+ for (String key : archetypeRequiredParameters.stringPropertyNames()) {
+ props.setProperty(key, archetypeRequiredParameters.getProperty(key));
+ }
+ }
+
+ MavenProject parent = maven.readProject(getDefaultArchetypePom(new File(targetDir, "pom.xml")));
+ System.setProperties((Properties) sysProps.clone());
+
+ maven.execute(parent,
+ Collections.singletonList("archetype:generate"),
+ eventMonitor,
+ new ConsoleDownloadMonitor(),
+ props,
+ targetDir);
+
+
+ System.setProperties((Properties) sysProps.clone());
+ targetDir = new File(targetDir, props.getProperty("artifactId"));
+ MavenProject prj = maven.readProject(new File(targetDir, "pom.xml"));
+
+ maven.execute(prj,
+ Collections.singletonList("package"),
+ eventMonitor,
+ new ConsoleDownloadMonitor(),
+ new Properties(),
+ targetDir);
+ }
+
+ private File getDefaultArchetypePom(File pomFile) throws IOException {
+ URL archetypePom = getClass().getClassLoader().getResource("archetype-pom.xml");
+ FileUtils.copyURLToFile(archetypePom, pomFile);
+ return pomFile;
+ }
+}
Index: archetypes/karaf-archetypes-itests/src/test/resources/archetype-pom.xml
===================================================================
--- archetypes/karaf-archetypes-itests/src/test/resources/archetype-pom.xml (revision 0)
+++ archetypes/karaf-archetypes-itests/src/test/resources/archetype-pom.xml (revision 0)
@@ -0,0 +1,33 @@
+
+
+
+
+ 4.0.0
+
+ org.apache.karaf
+ dummy
+ Archetype Manager
+ 2.0.1-SNAPSHOT
+ pom
+
+
Index: archetypes/karaf-archetypes-itests/pom.xml
===================================================================
--- archetypes/karaf-archetypes-itests/pom.xml (revision 0)
+++ archetypes/karaf-archetypes-itests/pom.xml (revision 0)
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ archetypes
+ org.apache.karaf
+ 2.0.1-SNAPSHOT
+
+ org.apache.karaf.archetypes
+ karaf-archetypes-itests
+ 2.0.1-SNAPSHOT
+ Apache Karaf :: Archetypes :: ITests
+
+
+
+ classworlds
+ classworlds
+ 1.1
+
+
+
+ org.apache.maven
+ maven-embedder
+ 2.0.4
+
+
+
+ commons-lang
+ commons-lang
+ 2.1
+
+
+
+ org.apache.maven
+ maven-project
+ 2.0.9
+
+
+
+ org.apache.maven
+ maven-core
+ 2.0.9
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-archetype-plugin
+ 2.0-alpha-5
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ -Dmaven.repo.local=${settings.localRepository}
+ always
+ ${basedir}
+
+ **/*Test.*
+
+
+
+
+
+
Index: archetypes/karaf-command-archetype/src/test/resources/projects/basic/archetype.properties
===================================================================
--- archetypes/karaf-command-archetype/src/test/resources/projects/basic/archetype.properties (revision 0)
+++ archetypes/karaf-command-archetype/src/test/resources/projects/basic/archetype.properties (revision 0)
@@ -0,0 +1,7 @@
+#Mon Jul 19 10:12:55 EEST 2010
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
+scope=scp
+command=cmd
+description=Test Command
Index: archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml (revision 0)
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+ src/main/java
+
+ **/*.java
+
+
+
+ src/main/resources
+
+ **/*.xml
+ **/*.properties
+
+
+
+ src/test/java
+
+ **/*.java
+
+
+
+
+
+ pom.xml
+
+
+
+
+
+ NOTICE
+
+
+
+
Index: archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype.xml
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype.xml (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/META-INF/maven/archetype.xml (revision 0)
@@ -0,0 +1,22 @@
+
+
+
+ karaf-command-archetype
+
Index: archetypes/karaf-command-archetype/src/main/resources/archetype-resources/NOTICE
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/archetype-resources/NOTICE (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/archetype-resources/NOTICE (revision 0)
@@ -0,0 +1,21 @@
+Apache Felix Karaf
+Copyright 2010 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+
+II. Used Software
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+
+III. License Summary
+- Apache License 2.0
Index: archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/test/java/__command__Test.java
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/test/java/__command__Test.java (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/test/java/__command__Test.java (revision 0)
@@ -0,0 +1,46 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * 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 ${package};
+
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link ${command}}
+ */
+@SuppressWarnings("unchecked")
+public class ${command}Test extends TestCase {
+
+ private ${command} command;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testCommand() {
+
+ }
+}
Index: archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/java/__command__.java
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/java/__command__.java (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/java/__command__.java (revision 0)
@@ -0,0 +1,36 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+#set( $cmd = $command.toLowerCase())
+/*
+ * 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 ${package};
+
+import org.apache.felix.gogo.commands.Command;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+
+
+/**
+ * Displays the last log entries
+ */
+@Command(scope = "${scope}", name = "${cmd}", description = "${description}")
+public class ${command} extends OsgiCommandSupport {
+
+ protected Object doExecute() throws Exception {
+ return null;
+ }
+}
Index: archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/resources/OSGI-INF/blueprint/shell-log.xml
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/resources/OSGI-INF/blueprint/shell-log.xml (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/archetype-resources/src/main/resources/OSGI-INF/blueprint/shell-log.xml (revision 0)
@@ -0,0 +1,33 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+#set( $cmd = $command.toLowerCase())
+
+
+
+
+
+
+
+
+
+
+
Index: archetypes/karaf-command-archetype/src/main/resources/archetype-resources/pom.xml
===================================================================
--- archetypes/karaf-command-archetype/src/main/resources/archetype-resources/pom.xml (revision 0)
+++ archetypes/karaf-command-archetype/src/main/resources/archetype-resources/pom.xml (revision 0)
@@ -0,0 +1,83 @@
+
+
+
+
+
+ 4.0.0
+
+
+ org.apache.karaf.shell
+ shell
+ 2.0.1-SNAPSHOT
+
+
+ ${groupId}
+ ${artifactId}
+ bundle
+ ${version}
+ Apache Karaf :: Shell ${scope} Commands
+
+ Provides the OSGi ${scope} commands
+
+
+ ${basedir}/../../etc/appended-resources
+
+
+
+
+ org.apache.karaf.shell
+ org.apache.karaf.shell.console
+ 2.0.1-SNAPSHOT
+
+
+
+ org.apache.felix
+ org.osgi.core
+ provided
+
+
+
+ org.apache.felix
+ org.osgi.compendium
+ provided
+
+
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+
+
+ ${project.artifactId}
+ ${package}*;version=${project.version}
+ !${project.artifactId}*,
+ org.osgi.service.command,
+ org.apache.felix.gogo.commands,
+ org.apache.karaf.shell.console,
+ *
+ !*
+ <_versionpolicy>${bnd.version.policy}
+
+
+
+
+
+
Index: archetypes/karaf-command-archetype/pom.xml
===================================================================
--- archetypes/karaf-command-archetype/pom.xml (revision 0)
+++ archetypes/karaf-command-archetype/pom.xml (revision 0)
@@ -0,0 +1,43 @@
+
+
+ 4.0.0
+
+ org.apache.karaf.archetypes
+ karaf-command-archetype
+ 2.0.1-SNAPSHOT
+
+ Apache Karaf :: Command Archetype
+
+
+
+
+ org.apache.maven.archetype
+ archetype-packaging
+ 2.0-alpha-5
+
+
+
+
+
+
+ maven-archetype-plugin
+ 2.0-alpha-5
+ true
+
+
+
+
+
+
+
Index: archetypes/pom.xml
===================================================================
--- archetypes/pom.xml (revision 0)
+++ archetypes/pom.xml (revision 0)
@@ -0,0 +1,39 @@
+
+
+
+ 4.0.0
+
+ org.apache.karaf
+ karaf
+ 2.0.1-SNAPSHOT
+
+
+ org.apache.karaf
+ archetypes
+ 2.0.1-SNAPSHOT
+
+ Apache Karaf :: Archetypes
+ pom
+
+
+
+ karaf-command-archetype
+ karaf-archetypes-itests
+
+
+
\ No newline at end of file