You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2013/08/02 15:25:00 UTC
svn commit: r1509693 - in /karaf/trunk/tooling/karaf-maven-plugin: ./
src/main/java/org/apache/karaf/tooling/features/
src/main/java/org/apache/karaf/tooling/features/model/
src/main/java/org/apache/karaf/tooling/instances/
src/main/java/org/apache/kar...
Author: cschneider
Date: Fri Aug 2 13:24:59 2013
New Revision: 1509693
URL: http://svn.apache.org/r1509693
Log:
KARAF-2425 Cleanup karaf maven plugin
Added:
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java (with props)
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java (with props)
Modified:
karaf/trunk/tooling/karaf-maven-plugin/NOTICE
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddToRepositoryMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ManifestUtils.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MavenUtil.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/Node.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ResolutionListenerImpl.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateDescriptorMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/instances/CreateArchiveMojo.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/url/WarURLHandler.java
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java
karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/ManifestUtilsTest.java
Modified: karaf/trunk/tooling/karaf-maven-plugin/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/NOTICE?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/NOTICE (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/NOTICE Fri Aug 2 13:24:59 2013
@@ -1,71 +1,71 @@
-Apache Karaf
-Copyright 2010-2013 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.
-
-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.
-
-This product includes software developed at
-OW2 (http://www.ow2.org/).
-Licensed under the BSD License.
-
-This product includes software developed at
-OPS4J (http://www.ops4j.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-Eclipse Foundation (http://www.eclipse.org/).
-Licensed under the EPL.
-
-This product includes software written by
-Antony Lesuisse.
-Licensed under Public Domain.
-
-
-II. Used Software
-
-This product uses software developed at
-FUSE Source (http://www.fusesource.org/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-AOP Alliance (http://aopalliance.sourceforge.net/).
-Licensed under the Public Domain.
-
-This product uses software developed at
-Tanuki Software (http://www.tanukisoftware.com/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-Jasypt (http://jasypt.sourceforge.net/).
-Licensed under the Apache License 2.0.
-
-This product uses software developed at
-JLine (http://jline.sourceforge.net).
-Licensed under the BSD License.
-
-This product uses software developed at
-SLF4J (http://www.slf4j.org/).
-Licensed under the MIT License.
-
-This product uses software developed at
-SpringSource (http://www.springsource.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software from http://www.json.org.
-Copyright (c) 2002 JSON.org
-
-
-III. License Summary
-- Apache License 2.0
-- BSD License
-- EPL License
-- MIT License
+Apache Karaf
+Copyright 2010-2013 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.
+
+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.
+
+This product includes software developed at
+OW2 (http://www.ow2.org/).
+Licensed under the BSD License.
+
+This product includes software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Eclipse Foundation (http://www.eclipse.org/).
+Licensed under the EPL.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+AOP Alliance (http://aopalliance.sourceforge.net/).
+Licensed under the Public Domain.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Jasypt (http://jasypt.sourceforge.net/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product uses software developed at
+SpringSource (http://www.springsource.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
+- EPL License
+- MIT License
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddToRepositoryMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddToRepositoryMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddToRepositoryMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/AddToRepositoryMojo.java Fri Aug 2 13:24:59 2013
@@ -17,41 +17,27 @@
*/
package org.apache.karaf.tooling.features;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
+import org.apache.karaf.tooling.features.model.Feature;
+import org.apache.karaf.tooling.features.model.Repository;
import org.apache.karaf.tooling.utils.MojoSupport;
import org.apache.maven.artifact.Artifact;
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.AbstractArtifactResolutionException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
/**
- * Generates the features XML file
+ * Add features to a repository directory
*
* @goal features-add-to-repository
* @phase compile
@@ -124,28 +110,11 @@ public class AddToRepositoryMojo extends
Package p = Package.getPackage("org.apache.karaf.tooling.features");
karafVersion = p.getImplementationVersion();
}
- String karafCoreEnterpriseFeatureUrl = String.format(KARAF_CORE_ENTERPRISE_FEATURE_URL, karafVersion);
- Artifact enterpriseFeatureDescriptor = resourceToArtifact(karafCoreEnterpriseFeatureUrl, true);
- if (enterpriseFeatureDescriptor != null) {
- try {
- resolveBundle(enterpriseFeatureDescriptor, remoteRepos);
- descriptors.add(0, karafCoreEnterpriseFeatureUrl);
- } catch (Exception e) {
- getLog().warn("Can't add " + karafCoreEnterpriseFeatureUrl + " in the descriptors set");
- getLog().debug(e);
- }
- }
- String karafCoreStandardFeatureUrl = String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion);
- Artifact standardFeatureDescriptor = resourceToArtifact(karafCoreStandardFeatureUrl, true);
- if (standardFeatureDescriptor != null) {
- try {
- resolveBundle(standardFeatureDescriptor, remoteRepos);
- descriptors.add(0, karafCoreStandardFeatureUrl);
- } catch (Exception e) {
- getLog().warn("Can't add " + karafCoreStandardFeatureUrl + " in the descriptors set");
- getLog().debug(e);
- }
- }
+
+ addFeatureRepo(String.format(KARAF_CORE_ENTERPRISE_FEATURE_URL, karafVersion));
+ addFeatureRepo(String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion));
+ addFeatureRepo(String.format(KARAF_CORE_STANDARD_FEATURE_URL, karafVersion));
+
try {
Set<String> bundles = new HashSet<String>();
Map<String, Feature> featuresMap = new HashMap<String, Feature>();
@@ -178,9 +147,6 @@ public class AddToRepositoryMojo extends
}
}
- // bundles with explicitely specified remote repos. key -> bundle, value -> remote repo
- List<Artifact> explicitRepoBundles = new ArrayList<Artifact>();
-
getLog().info("Base repo: " + localRepo.getUrl());
int currentBundle = 0;
for (String bundle : bundles) {
@@ -196,41 +162,45 @@ public class AddToRepositoryMojo extends
if (artifact == null) {
continue;
}
- if (artifact.getRepository() != null) {
- explicitRepoBundles.add(artifact);
- } else {
- // bundle URL without repository information are resolved now
- resolveBundle(artifact, remoteRepos);
- }
- }
- // resolving all bundles with explicitly specified remote repository
- for (Artifact explicitBundle : explicitRepoBundles) {
- resolveBundle(explicitBundle, Collections.singletonList(explicitBundle.getRepository()));
+ resolveAndCopyArtifact(artifact, remoteRepos);
}
+
if (copyFileBasedDescriptors != null) {
for (CopyFileBasedDescriptor fileBasedDescriptor : copyFileBasedDescriptors) {
- copy(new FileInputStream(fileBasedDescriptor.getSourceFile()),
- repository,
- fileBasedDescriptor.getTargetFileName(),
- fileBasedDescriptor.getTargetDirectory(),
- new byte[8192]);
+ File destDir = new File(repository, fileBasedDescriptor.getTargetDirectory());
+ File destFile = new File(destDir, fileBasedDescriptor.getTargetFileName());
+ copy(fileBasedDescriptor.getSourceFile(), destFile);
}
}
- } catch (MojoExecutionException e) {
- throw e;
- } catch (MojoFailureException e) {
- throw e;
} catch (Exception e) {
throw new MojoExecutionException("Error populating repository", e);
}
}
- private void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap)
- throws Exception {
+ private void addFeatureRepo(String featureUrl) throws MojoExecutionException {
+ Artifact featureDescArtifact = resourceToArtifact(featureUrl, true);
+ if (featureDescArtifact == null) {
+ return;
+ }
+ try {
+ resolveAndCopyArtifact(featureDescArtifact, remoteRepos);
+ descriptors.add(0, featureUrl);
+ } catch (Exception e) {
+ getLog().warn("Can't add " + featureUrl + " in the descriptors set");
+ getLog().debug(e);
+ }
+ }
+
+ private void retrieveDescriptorsRecursively(String uri, Set<String> bundles, Map<String, Feature> featuresMap) {
// let's ensure a mvn: based url is sitting in the local repo before we try reading it
- Artifact descriptor = resourceToArtifact(uri, true);
+ Artifact descriptor;
+ try {
+ descriptor = resourceToArtifact(uri, true);
+ } catch (MojoExecutionException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
if (descriptor != null) {
- resolveBundle(descriptor, remoteRepos);
+ resolveAndCopyArtifact(descriptor, remoteRepos);
}
if (includeMvnBasedDescriptors) {
bundles.add(uri);
@@ -246,38 +216,44 @@ public class AddToRepositoryMojo extends
}
}
- // resolves the bundle in question
- // TODO neither remoteRepos nor bundle's Repository are used, only the local repo?????
- private void resolveBundle(Artifact bundle, List<ArtifactRepository> remoteRepos) throws IOException,
- MojoFailureException {
- // TODO consider DefaultRepositoryLayout
- String dir =
- bundle.getGroupId().replace('.', '/') + "/" + bundle.getArtifactId() + "/" + bundle.getBaseVersion() + "/";
- String name =
- bundle.getArtifactId() + "-" + bundle.getBaseVersion()
- + (bundle.getClassifier() != null ? "-" + bundle.getClassifier() : "") + "." + bundle.getType();
-
+ /**
+ * Resolves and copies the given artifact to the repository path.
+ * Prefers to resolve using the repository of the artifact if present.
+ *
+ * @param artifact
+ * @param remoteRepos
+ */
+ @SuppressWarnings("deprecation")
+ private void resolveAndCopyArtifact(Artifact artifact, List<ArtifactRepository> remoteRepos) {
try {
- getLog().info("Copying bundle: " + bundle);
- resolver.resolve(bundle, remoteRepos, localRepo);
- copy(new FileInputStream(bundle.getFile()),
- repository,
- name,
- dir,
- new byte[8192]);
- } catch (ArtifactResolutionException e) {
- if (failOnArtifactResolutionError) {
- throw new MojoFailureException("Can't resolve bundle " + bundle, e);
- }
- getLog().error("Can't resolve bundle " + bundle, e);
- } catch (ArtifactNotFoundException e) {
+ getLog().info("Copying artifact: " + artifact);
+ List<ArtifactRepository> usedRemoteRepos = artifact.getRepository() != null ?
+ Collections.singletonList(artifact.getRepository())
+ : remoteRepos;
+ resolver.resolve(artifact, usedRemoteRepos, localRepo);
+ File destFile = new File(repository, getRelativePath(artifact));
+ copy(artifact.getFile(), destFile);
+ } catch (AbstractArtifactResolutionException e) {
if (failOnArtifactResolutionError) {
- throw new MojoFailureException("Can't resolve bundle " + bundle, e);
+ throw new RuntimeException("Can't resolve bundle " + artifact, e);
}
- getLog().error("Can't resolve bundle " + bundle, e);
+ getLog().error("Can't resolve bundle " + artifact, e);
}
}
+ /**
+ * Get relative path for artifact
+ * TODO consider DefaultRepositoryLayout
+ * @param artifact
+ * @return relative path of the given artifact in a default repo layout
+ */
+ private String getRelativePath(Artifact artifact) {
+ String dir = artifact.getGroupId().replace('.', '/') + "/" + artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/";
+ String name = artifact.getArtifactId() + "-" + artifact.getBaseVersion()
+ + (artifact.getClassifier() != null ? "-" + artifact.getClassifier() : "") + "." + artifact.getType();
+ return dir + name;
+ }
+
private void addFeatures(List<String> features, Set<String> featuresBundles, Set<String> transitiveFeatures,
Map<String, Feature> featuresMap) {
for (String feature : features) {
@@ -322,195 +298,4 @@ public class AddToRepositoryMojo extends
}
}
- public static void copy(
- InputStream is, File dir, String destName, String destDir, byte[] buffer)
- throws IOException {
- if (destDir == null) {
- destDir = "";
- }
-
- // Make sure the target directory exists and
- // that is actually a directory.
- File targetDir = new File(dir, destDir);
- if (!targetDir.exists()) {
- if (!targetDir.mkdirs()) {
- throw new IOException("Unable to create target directory: "
- + targetDir);
- }
- } else if (!targetDir.isDirectory()) {
- throw new IOException("Target is not a directory: "
- + targetDir);
- }
-
- BufferedOutputStream bos = new BufferedOutputStream(
- new FileOutputStream(new File(targetDir, destName)));
- int count = 0;
- while ((count = is.read(buffer)) > 0) {
- bos.write(buffer, 0, count);
- }
- bos.close();
- }
-
- public static class Feature {
-
- private String name;
- private String version;
- private List<String> dependencies = new ArrayList<String>();
- private List<String> bundles = new ArrayList<String>();
- private Map<String, Map<String, String>> configs = new HashMap<String, Map<String, String>>();
- private List<String> configFiles = new ArrayList<String>();
-
- public Feature(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-
- public List<String> getDependencies() {
- return dependencies;
- }
-
- public List<String> getBundles() {
- return bundles;
- }
-
- public Map<String, Map<String, String>> getConfigurations() {
- return configs;
- }
-
- public List<String> getConfigFiles() {
- return configFiles;
- }
-
- public void addDependency(String dependency) {
- dependencies.add(dependency);
- }
-
- public void addBundle(String bundle) {
- bundles.add(bundle);
- }
-
- public void addConfig(String name, Map<String, String> properties) {
- configs.put(name, properties);
- }
-
- public void addConfigFile(String configFile) {
- configFiles.add(configFile);
- }
- }
-
- public static class Repository {
-
- private URI uri;
- private List<Feature> features;
- private List<String> repositories;
-
- public Repository(URI uri) {
- this.uri = uri;
- }
-
- public URI getURI() {
- return uri;
- }
-
- public Feature[] getFeatures() throws Exception {
- if (features == null) {
- loadFeatures();
- }
- return features.toArray(new Feature[features.size()]);
- }
-
- public String[] getDefinedRepositories() throws Exception {
- if (repositories == null) {
- loadRepositories();
- }
- return repositories.toArray(new String[repositories.size()]);
- }
-
- private void loadRepositories() throws IOException {
- try {
- repositories = new ArrayList<String>();
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- Document doc = factory.newDocumentBuilder().parse(uri.toURL().openStream());
- NodeList nodes = doc.getDocumentElement().getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- org.w3c.dom.Node node = nodes.item(i);
- if (!(node instanceof Element) || !"repository".equals(node.getNodeName())) {
- continue;
- }
- Element e = (Element) nodes.item(i);
- repositories.add(e.getTextContent().trim());
- }
- } catch (SAXException e) {
- throw (IOException) new IOException().initCause(e);
- } catch (ParserConfigurationException e) {
- throw (IOException) new IOException().initCause(e);
- }
- }
-
- private void loadFeatures() throws IOException {
- try {
- features = new ArrayList<Feature>();
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- Document doc = factory.newDocumentBuilder().parse(uri.toURL().openStream());
- NodeList nodes = doc.getDocumentElement().getChildNodes();
- for (int i = 0; i < nodes.getLength(); i++) {
- org.w3c.dom.Node node = nodes.item(i);
- if (!(node instanceof Element) || !"feature".equals(node.getNodeName())) {
- continue;
- }
- Element e = (Element) nodes.item(i);
- String name = e.getAttribute("name");
- String version = e.getAttribute("version");
- Feature f = new Feature(name);
- f.setVersion(version);
- NodeList featureNodes = e.getElementsByTagName("feature");
- for (int j = 0; j < featureNodes.getLength(); j++) {
- Element b = (Element) featureNodes.item(j);
- f.addDependency(b.getTextContent());
- }
- NodeList configNodes = e.getElementsByTagName("config");
- for (int j = 0; j < configNodes.getLength(); j++) {
- Element c = (Element) configNodes.item(j);
- String cfgName = c.getAttribute("name");
- String data = c.getTextContent();
- Properties properties = new Properties();
- properties.load(new ByteArrayInputStream(data.getBytes()));
- Map<String, String> hashtable = new Hashtable<String, String>();
- for (Object key : properties.keySet()) {
- String n = key.toString();
- hashtable.put(n, properties.getProperty(n));
- }
- f.addConfig(cfgName, hashtable);
- }
- NodeList configFileNodes = e.getElementsByTagName("configfile");
- for (int j = 0; j < configFileNodes.getLength(); j++) {
- Element c = (Element) configFileNodes.item(j);
- f.addConfigFile(c.getTextContent());
- }
- NodeList bundleNodes = e.getElementsByTagName("bundle");
- for (int j = 0; j < bundleNodes.getLength(); j++) {
- Element b = (Element) bundleNodes.item(j);
- f.addBundle(b.getTextContent());
- }
- features.add(f);
- }
- } catch (SAXException e) {
- throw (IOException) new IOException().initCause(e);
- } catch (ParserConfigurationException e) {
- throw (IOException) new IOException().initCause(e);
- }
- }
-
- }
}
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java Fri Aug 2 13:24:59 2013
@@ -192,7 +192,8 @@ public class CreateKarMojo extends MojoS
*
* @param bundles
*/
- private File createArchive(List<Artifact> bundles) throws MojoExecutionException {
+ @SuppressWarnings("deprecation")
+ private File createArchive(List<Artifact> bundles) throws MojoExecutionException {
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
File archiveFile = getArchiveFile(outputDirectory, finalName, classifier);
@@ -219,7 +220,7 @@ public class CreateKarMojo extends MojoS
// archive.addManifestEntry(Constants.BUNDLE_SYMBOLICNAME, project.getArtifactId());
//include the feature.xml
- Artifact featureArtifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "xml", KarArtifactInstaller.FEATURE_CLASSIFIER);
+ Artifact featureArtifact = factory.createArtifactWithClassifier(project.getGroupId(), project.getArtifactId(), project.getVersion(), "xml", KarArtifactInstaller.FEATURE_CLASSIFIER);
jarArchiver.addFile(featuresFile, repositoryPath + layout.pathOf(featureArtifact));
if (featureArtifact.isSnapshot()) {
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/DependencyHelper.java Fri Aug 2 13:24:59 2013
@@ -78,24 +78,12 @@ public class DependencyHelper {
*/
private final List<RemoteRepository> projectRepos;
- /**
- * The project's remote repositories to use for the resolution of plugins and their dependencies.
- *
- * @parameter default-value="${project.remotePluginRepositories}"
- * @required
- * @readonly
- */
- private final List<RemoteRepository> pluginRepos;
-
//dependencies we are interested in
protected Map<Artifact, String> localDependencies;
//log of what happened during search
protected String treeListing;
-
-
- public DependencyHelper(List<RemoteRepository> pluginRepos, List<RemoteRepository> projectRepos, RepositorySystemSession repoSession, RepositorySystem repoSystem) {
- this.pluginRepos = pluginRepos;
+ public DependencyHelper(List<RemoteRepository> projectRepos, RepositorySystemSession repoSession, RepositorySystem repoSystem) {
this.projectRepos = projectRepos;
this.repoSession = repoSession;
this.repoSystem = repoSystem;
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java Fri Aug 2 13:24:59 2013
@@ -74,7 +74,6 @@ import static org.apache.karaf.deployer.
* @description Generates the features XML file starting with an optional source feature.xml and adding
* project dependencies as bundles and feature/car dependencies
*/
-@SuppressWarnings("unchecked")
public class GenerateDescriptorMojo extends AbstractLogEnabled implements Mojo {
/**
@@ -228,15 +227,6 @@ public class GenerateDescriptorMojo exte
private List<RemoteRepository> projectRepos;
/**
- * The project's remote repositories to use for the resolution of plugins and their dependencies.
- *
- * @parameter default-value="${project.remotePluginRepositories}"
- * @required
- * @readonly
- */
- private List<RemoteRepository> pluginRepos;
-
- /**
* @component role="org.apache.maven.shared.filtering.MavenResourcesFiltering" role-hint="default"
* @required
* @readonly
@@ -268,7 +258,7 @@ public class GenerateDescriptorMojo exte
public void execute() throws MojoExecutionException, MojoFailureException {
try {
- DependencyHelper dependencyHelper = new DependencyHelper(pluginRepos, projectRepos, repoSession, repoSystem);
+ DependencyHelper dependencyHelper = new DependencyHelper(projectRepos, repoSession, repoSystem);
dependencyHelper.getDependencies(project, includeTransitiveDependency);
this.localDependencies = dependencyHelper.getLocalDependencies();
this.treeListing = dependencyHelper.getTreeListing();
@@ -411,6 +401,7 @@ public class GenerateDescriptorMojo exte
if (m == null) {
getLogger().warn("Manifest not present in the first entry of the zip - " + file.getName());
}
+ jar.close();
return m;
} finally {
if (is != null) { // just in case when we did not open bundle
@@ -544,8 +535,6 @@ public class GenerateDescriptorMojo exte
*/
protected Map<String, String> systemProperties;
- private Map<String, String> previousSystemProperties;
-
private void checkChanges(Features newFeatures, ObjectFactory objectFactory) throws Exception, IOException, JAXBException, XMLStreamException {
if (checkDependencyChange) {
//combine all the dependencies to one feature and strip out versions
@@ -704,7 +693,8 @@ public class GenerateDescriptorMojo exte
+ ", i.e. build is platform dependent!");
}
targetFile.getParentFile().mkdirs();
- List filters = mavenFileFilter.getDefaultFilterWrappers(project, null, true, session, null);
+ @SuppressWarnings("rawtypes")
+ List filters = mavenFileFilter.getDefaultFilterWrappers(project, null, true, session, null);
mavenFileFilter.copyFile(sourceFile, targetFile, true, filters, encoding, true);
} catch (MavenFilteringException e) {
throw new MojoExecutionException(e.getMessage(), e);
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java Fri Aug 2 13:24:59 2013
@@ -20,7 +20,6 @@ package org.apache.karaf.tooling.feature
import static java.lang.String.format;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -185,6 +184,7 @@ public class InstallKarsMojo extends Moj
*/
private List<Feature> localRepoFeatures = new ArrayList<Feature>();
+ @SuppressWarnings("deprecation")
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
systemDirectory.mkdirs();
@@ -211,7 +211,6 @@ public class InstallKarsMojo extends Moj
Collection<Artifact> dependencies = project.getDependencyArtifacts();
StringBuilder buf = new StringBuilder();
- byte[] buffer = new byte[4096];
for (Artifact artifact : dependencies) {
dontAddToStartup = "runtime".equals(artifact.getScope());
if ("kar".equals(artifact.getType()) && acceptScope(artifact)) {
@@ -242,14 +241,8 @@ public class InstallKarsMojo extends Moj
if (!target.exists()) {
target.getParentFile().mkdirs();
try {
- InputStream is = new FileInputStream(source);
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
- int count = 0;
- while ((count = is.read(buffer)) > 0) {
- bos.write(buffer, 0, count);
- }
- bos.close();
- } catch (IOException e) {
+ copy(source, target);
+ } catch (RuntimeException e) {
getLog().error("Could not copy features " + uri + " from source file " + source, e);
}
@@ -276,13 +269,13 @@ public class InstallKarsMojo extends Moj
}
// install bundles listed in startup properties that weren't in kars into the system dir
- Set keySet = startupProperties.keySet();
+ Set<?> keySet = startupProperties.keySet();
for (Object keyObject : keySet) {
String key = (String) keyObject;
String path = MavenUtil.pathFromMaven(key);
File target = new File(system.resolve(path));
if (!target.exists()) {
- install(buffer, key, target);
+ install(key, target);
}
}
@@ -296,7 +289,7 @@ public class InstallKarsMojo extends Moj
if (!test.exists()) {
File target = new File(system.resolve(path));
if (!target.exists()) {
- install(buffer, key, target);
+ install(key, target);
Artifact artifact = MavenUtil.mvnToArtifact(key);
if (artifact.isSnapshot()) {
// generate maven-metadata-local.xml for the artifact
@@ -309,7 +302,7 @@ public class InstallKarsMojo extends Moj
MavenUtil.generateMavenMetadata(artifact, metadataTarget);
} else {
// copy the metadata to the target
- copy(buffer, metadataSource, metadataTarget);
+ copy(metadataSource, metadataTarget);
}
} catch (IOException ioException) {
getLog().warn(ioException);
@@ -337,27 +330,12 @@ public class InstallKarsMojo extends Moj
}
}
- private void install(byte[] buffer, String key, File target) throws MojoFailureException {
+ private void install(String key, File target) throws MojoFailureException {
File source = resolve(key);
target.getParentFile().mkdirs();
- try {
- copy(buffer, source, target);
- } catch (IOException e) {
- getLog().error("Could not copy bundle " + key, e);
- }
+ copy(source, target);
}
- private void copy(byte[] buffer, File source, File target) throws IOException {
- target.getParentFile().mkdirs();
- InputStream is = new FileInputStream(source);
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target));
- int count = 0;
- while ((count = is.read(buffer)) > 0) {
- bos.write(buffer, 0, count);
- }
- bos.close();
- }
-
private boolean acceptScope(Artifact artifact) {
return "compile".equals(artifact.getScope()) || "runtime".equals(artifact.getScope());
}
@@ -616,6 +594,7 @@ public class InstallKarsMojo extends Moj
private Map<String, Layout> layout;
private Map<String, String> storage;
+ @SuppressWarnings("unchecked")
public CommentProperties() {
layout = (Map<String, Layout>) getField("layout");
storage = (Map<String, String>) getField("storage");
@@ -651,40 +630,6 @@ public class InstallKarsMojo extends Moj
return result;
}
- /**
- * The list of possible key/value separators
- */
- private static final char[] SEPARATORS = new char[]{ '=', ':' };
-
- /**
- * The white space characters used as key/value separators.
- */
- private static final char[] WHITE_SPACE = new char[]{ ' ', '\t', '\f' };
-
- /**
- * Escape the separators in the key.
- *
- * @param key the key
- * @return the escaped key
- */
- private static String escapeKey(String key) {
- StringBuffer newkey = new StringBuffer();
-
- for (int i = 0; i < key.length(); i++) {
- char c = key.charAt(i);
-
- if (contains(SEPARATORS, c) || contains(WHITE_SPACE, c)) {
- // escape the separator
- newkey.append('\\');
- newkey.append(c);
- } else {
- newkey.append(c);
- }
- }
-
- return newkey.toString();
- }
-
}
}
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ManifestUtils.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ManifestUtils.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ManifestUtils.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ManifestUtils.java Fri Aug 2 13:24:59 2013
@@ -124,7 +124,8 @@ public class ManifestUtils {
return bsn;
}
- public static VersionRange getVersionRange(Clause clause)
+ @SuppressWarnings("deprecation")
+ public static VersionRange getVersionRange(Clause clause)
{
String v = clause.getAttribute(Constants.VERSION_ATTRIBUTE);
if (v == null)
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MavenUtil.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MavenUtil.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MavenUtil.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/MavenUtil.java Fri Aug 2 13:24:59 2013
@@ -28,8 +28,6 @@ import java.util.regex.Pattern;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.artifact.repository.metadata.Metadata;
import org.apache.maven.artifact.repository.metadata.Snapshot;
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/Node.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/Node.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/Node.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/Node.java Fri Aug 2 13:24:59 2013
@@ -23,11 +23,11 @@ import java.util.HashSet;
import org.apache.maven.artifact.Artifact;
public class Node {
- private Set children = new HashSet();
- private Set parents = new HashSet();
+ private Set<Node> children = new HashSet<Node>();
+ private Set<Node> parents = new HashSet<Node>();
private Artifact artifact;
- public Set getChildren() {
+ public Set<Node> getChildren() {
return children;
}
@@ -35,15 +35,15 @@ public class Node {
return artifact;
}
- public Set getParents() {
+ public Set<Node> getParents() {
return parents;
}
- public void setChildren(Set children) {
+ public void setChildren(Set<Node> children) {
this.children = children;
}
- public void setParents(Set parents) {
+ public void setParents(Set<Node> parents) {
this.parents = parents;
}
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ResolutionListenerImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ResolutionListenerImpl.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ResolutionListenerImpl.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ResolutionListenerImpl.java Fri Aug 2 13:24:59 2013
@@ -29,8 +29,8 @@ import org.apache.maven.artifact.version
import org.apache.maven.plugin.logging.Log;
public class ResolutionListenerImpl implements ResolutionListener {
- private Stack parents = new Stack();
- private Map artifacts = new HashMap();
+ private Stack<Node> parents = new Stack<Node>();
+ private Map<String, Node> artifacts = new HashMap<String, Node>();
private Node rootNode;
private Log log;
@@ -97,8 +97,8 @@ public class ResolutionListenerImpl impl
protected void print(Node node, String string) {
// getLog().debug(string + rootNode.getArtifact());
- for (Iterator iter = node.getChildren().iterator(); iter.hasNext();) {
- Node n = (Node) iter.next();
+ for (Iterator<Node> iter = node.getChildren().iterator(); iter.hasNext();) {
+ Node n = iter.next();
print(n, string + " ");
}
}
@@ -147,7 +147,7 @@ public class ResolutionListenerImpl impl
return (Node) artifacts.get(artifact.getDependencyConflictId());
}
- public Collection getArtifacts() {
+ public Collection<Node> getArtifacts() {
return artifacts.values();
}
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateDescriptorMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateDescriptorMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateDescriptorMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/ValidateDescriptorMojo.java Fri Aug 2 13:24:59 2013
@@ -60,7 +60,7 @@ import static org.apache.karaf.tooling.f
* @inheritByDefault true
* @description Validates the features XML file
*/
-@SuppressWarnings("unchecked")
+@SuppressWarnings("deprecation")
public class ValidateDescriptorMojo extends MojoSupport {
private static final String MVN_URI_PREFIX = "mvn:";
@@ -517,7 +517,6 @@ public class ValidateDescriptorMojo exte
*/
private Manifest getManifest(String bundle, Object artifact) throws ArtifactResolutionException, ArtifactNotFoundException,
ZipException, IOException {
- ZipFile file = null;
if (!(artifact instanceof Artifact)) {
//not resolved as mvn artifact, so it's non-mvn protocol, just use the CustomBundleURLStreamHandlerFactory
// to open stream
@@ -535,14 +534,13 @@ public class ValidateDescriptorMojo exte
if (m == null) {
throw new IOException("Manifest not present in the first entry of the zip");
}
-
+ silentClose(jar);
return m;
} finally {
- if (is != null) { // just in case when we did not open bundle
- is.close();
- }
+ silentClose(is);
}
} else {
+ ZipFile file = null;
Artifact mvnArtifact = (Artifact) artifact;
File localFile = new File(localRepo.pathOf(mvnArtifact));
if (localFile.exists()) {
@@ -560,6 +558,7 @@ public class ValidateDescriptorMojo exte
Manifest manifest = new Manifest(file.getInputStream(file.getEntry("META-INF/MANIFEST.MF")));
return manifest;
} finally {
+ silentClose(file);
System.setErr(original);
}
}
Added: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java?rev=1509693&view=auto
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java (added)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java Fri Aug 2 13:24:59 2013
@@ -0,0 +1,81 @@
+/**
+ *
+ * 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.tooling.features.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Feature {
+
+ private String name;
+ private String version;
+ private List<String> dependencies = new ArrayList<String>();
+ private List<String> bundles = new ArrayList<String>();
+ private Map<String, Map<String, String>> configs = new HashMap<String, Map<String, String>>();
+ private List<String> configFiles = new ArrayList<String>();
+
+ public Feature(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
+ public List<String> getDependencies() {
+ return dependencies;
+ }
+
+ public List<String> getBundles() {
+ return bundles;
+ }
+
+ public Map<String, Map<String, String>> getConfigurations() {
+ return configs;
+ }
+
+ public List<String> getConfigFiles() {
+ return configFiles;
+ }
+
+ public void addDependency(String dependency) {
+ dependencies.add(dependency);
+ }
+
+ public void addBundle(String bundle) {
+ bundles.add(bundle);
+ }
+
+ public void addConfig(String name, Map<String, String> properties) {
+ configs.put(name, properties);
+ }
+
+ public void addConfigFile(String configFile) {
+ configFiles.add(configFile);
+ }
+}
\ No newline at end of file
Propchange: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Feature.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java?rev=1509693&view=auto
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java (added)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java Fri Aug 2 13:24:59 2013
@@ -0,0 +1,133 @@
+/**
+ *
+ * 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.tooling.features.model;
+
+import java.io.ByteArrayInputStream;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class Repository {
+
+ private URI uri;
+ private List<Feature> features;
+ private List<String> repositories;
+
+ public Repository(URI uri) {
+ this.uri = uri;
+ }
+
+ public URI getURI() {
+ return uri;
+ }
+
+ public Feature[] getFeatures() {
+ if (features == null) {
+ loadFeatures();
+ }
+ return features.toArray(new Feature[features.size()]);
+ }
+
+ public String[] getDefinedRepositories() {
+ if (repositories == null) {
+ loadRepositories();
+ }
+ return repositories.toArray(new String[repositories.size()]);
+ }
+
+ private void loadRepositories() {
+ try {
+ repositories = new ArrayList<String>();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document doc = factory.newDocumentBuilder().parse(uri.toURL().openStream());
+ NodeList nodes = doc.getDocumentElement().getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ org.w3c.dom.Node node = nodes.item(i);
+ if (!(node instanceof Element) || !"repository".equals(node.getNodeName())) {
+ continue;
+ }
+ Element e = (Element) nodes.item(i);
+ repositories.add(e.getTextContent().trim());
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Error loading feature descriptors from " + this.uri, e);
+ }
+ }
+
+ private void loadFeatures() {
+ try {
+ features = new ArrayList<Feature>();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ Document doc = factory.newDocumentBuilder().parse(uri.toURL().openStream());
+ NodeList nodes = doc.getDocumentElement().getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ org.w3c.dom.Node node = nodes.item(i);
+ if (!(node instanceof Element) || !"feature".equals(node.getNodeName())) {
+ continue;
+ }
+ Element e = (Element) nodes.item(i);
+ String name = e.getAttribute("name");
+ String version = e.getAttribute("version");
+ Feature f = new Feature(name);
+ f.setVersion(version);
+ NodeList featureNodes = e.getElementsByTagName("feature");
+ for (int j = 0; j < featureNodes.getLength(); j++) {
+ Element b = (Element) featureNodes.item(j);
+ f.addDependency(b.getTextContent());
+ }
+ NodeList configNodes = e.getElementsByTagName("config");
+ for (int j = 0; j < configNodes.getLength(); j++) {
+ Element c = (Element) configNodes.item(j);
+ String cfgName = c.getAttribute("name");
+ String data = c.getTextContent();
+ Properties properties = new Properties();
+ properties.load(new ByteArrayInputStream(data.getBytes()));
+ Map<String, String> hashtable = new Hashtable<String, String>();
+ for (Object key : properties.keySet()) {
+ String n = key.toString();
+ hashtable.put(n, properties.getProperty(n));
+ }
+ f.addConfig(cfgName, hashtable);
+ }
+ NodeList configFileNodes = e.getElementsByTagName("configfile");
+ for (int j = 0; j < configFileNodes.getLength(); j++) {
+ Element c = (Element) configFileNodes.item(j);
+ f.addConfigFile(c.getTextContent());
+ }
+ NodeList bundleNodes = e.getElementsByTagName("bundle");
+ for (int j = 0; j < bundleNodes.getLength(); j++) {
+ Element b = (Element) bundleNodes.item(j);
+ f.addBundle(b.getTextContent());
+ }
+ features.add(f);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("Error loading features for " + this.uri, e);
+ }
+ }
+
+}
\ No newline at end of file
Propchange: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/model/Repository.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/instances/CreateArchiveMojo.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/instances/CreateArchiveMojo.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/instances/CreateArchiveMojo.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/instances/CreateArchiveMojo.java Fri Aug 2 13:24:59 2013
@@ -103,7 +103,8 @@ public class CreateArchiveMojo extends M
}
}
- private void archive(String type) throws IOException {
+ @SuppressWarnings("deprecation")
+ private void archive(String type) throws IOException {
Artifact artifact1 = factory.createArtifactWithClassifier(project.getArtifact().getGroupId(), project.getArtifact().getArtifactId(), project.getArtifact().getVersion(), type, "bin");
File target1 = archive(targetServerDirectory, destDir, artifact1);
projectHelper.attachArtifact( project, artifact1.getType(), null, target1 );
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/url/WarURLHandler.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/url/WarURLHandler.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/url/WarURLHandler.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/url/WarURLHandler.java Fri Aug 2 13:24:59 2013
@@ -17,14 +17,7 @@
*/
package org.apache.karaf.tooling.url;
-import org.apache.karaf.deployer.blueprint.BlueprintTransformer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
@@ -35,8 +28,6 @@ import java.net.URLStreamHandler;
*/
public class WarURLHandler extends URLStreamHandler {
- private final Logger logger = LoggerFactory.getLogger(WarURLHandler.class);
-
private static String SYNTAX = "war: war-uri";
private URL warURL;
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/utils/MojoSupport.java Fri Aug 2 13:24:59 2013
@@ -17,7 +17,12 @@
*/
package org.apache.karaf.tooling.utils;
+import java.io.BufferedOutputStream;
+import java.io.Closeable;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -37,8 +42,6 @@ import org.apache.maven.artifact.metadat
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
-import org.apache.maven.artifact.resolver.ArtifactCollector;
-import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
@@ -53,6 +56,7 @@ import org.apache.maven.project.MavenPro
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.settings.Proxy;
+@SuppressWarnings({"deprecation", "rawtypes", "unchecked"})
public abstract class MojoSupport extends AbstractMojo {
/**
@@ -154,7 +158,7 @@ public abstract class MojoSupport extend
n.getChildren().clear();
}
- protected Set getArtifacts(Node n, Set s) {
+ protected Set getArtifacts(Node n, Set s) {
if (!s.contains(n.getArtifact())) {
s.add(n.getArtifact());
for (Iterator iter = n.getChildren().iterator(); iter.hasNext();) {
@@ -457,4 +461,54 @@ public abstract class MojoSupport extend
return null;
}
}
+
+ protected void silentClose(Closeable closeable) {
+ if (closeable != null) {
+ try {
+ closeable.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+
+ protected void copy(File sourceFile, File destFile) {
+ File targetDir = destFile.getParentFile();
+ ensureDirExists(targetDir);
+
+ FileInputStream is = null;
+ BufferedOutputStream bos = null;
+ try {
+ is = new FileInputStream(sourceFile);
+ bos = new BufferedOutputStream(new FileOutputStream(destFile));
+ int count = 0;
+ byte[] buffer = new byte[8192];
+ while ((count = is.read(buffer)) > 0) {
+ bos.write(buffer, 0, count);
+ }
+ bos.close();
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ } finally {
+ silentClose(is);
+ silentClose(bos);
+ }
+ }
+
+
+ /**
+ * Make sure the target directory exists and
+ * that is actually a directory
+ * @param targetDir
+ * @throws IOException
+ */
+ private static void ensureDirExists(File targetDir) {
+ if (!targetDir.exists()) {
+ if (!targetDir.mkdirs()) {
+ throw new RuntimeException("Unable to create target directory: " + targetDir);
+ }
+ } else if (!targetDir.isDirectory()) {
+ throw new RuntimeException("Target is not a directory: " + targetDir);
+ }
+ }
}
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/AddToRepositoryMojoTest.java Fri Aug 2 13:24:59 2013
@@ -1,5 +1,6 @@
package org.apache.karaf.tooling.features;
+import org.apache.karaf.tooling.features.model.Repository;
import org.apache.maven.artifact.factory.DefaultArtifactFactory;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.artifact.handler.manager.DefaultArtifactHandlerManager;
@@ -19,7 +20,8 @@ import java.util.HashMap;
* To change this template use File | Settings | File Templates.
*/
public class AddToRepositoryMojoTest extends AddToRepositoryMojo {
- public AddToRepositoryMojoTest() throws NoSuchFieldException, IllegalAccessException {
+ @SuppressWarnings("rawtypes")
+ public AddToRepositoryMojoTest() throws NoSuchFieldException, IllegalAccessException {
factory = new DefaultArtifactFactory();
ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager();
Field f = factory.getClass().getDeclaredField("artifactHandlerManager");
@@ -39,7 +41,7 @@ public class AddToRepositoryMojoTest ext
@Test
public void testSimpleURL() throws Exception {
URL in = getClass().getClassLoader().getResource("input-repository.xml");
- AddToRepositoryMojo.Repository repo = new AddToRepositoryMojo.Repository(in.toURI());
+ Repository repo = new Repository(in.toURI());
String[] repos = repo.getDefinedRepositories();
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/BundleToArtifactTest.java Fri Aug 2 13:24:59 2013
@@ -34,7 +34,8 @@ import org.junit.Test;
public class BundleToArtifactTest extends MojoSupport {
- public BundleToArtifactTest() throws NoSuchFieldException, IllegalAccessException {
+ @SuppressWarnings("rawtypes")
+ public BundleToArtifactTest() throws NoSuchFieldException, IllegalAccessException {
factory = new DefaultArtifactFactory();
ArtifactHandlerManager artifactHandlerManager = new DefaultArtifactHandlerManager();
Field f = factory.getClass().getDeclaredField("artifactHandlerManager");
Modified: karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/ManifestUtilsTest.java
URL: http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/ManifestUtilsTest.java?rev=1509693&r1=1509692&r2=1509693&view=diff
==============================================================================
--- karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/ManifestUtilsTest.java (original)
+++ karaf/trunk/tooling/karaf-maven-plugin/src/test/java/org/apache/karaf/tooling/features/ManifestUtilsTest.java Fri Aug 2 13:24:59 2013
@@ -21,8 +21,6 @@ import static org.apache.karaf.tooling.f
import junit.framework.TestCase;
-import java.util.HashMap;
-
import org.apache.felix.utils.manifest.Attribute;
import org.apache.felix.utils.manifest.Clause;
import org.apache.felix.utils.manifest.Directive;