From 54ec59f792ff4c220b2db23a86b0613413989d38 Mon Sep 17 00:00:00 2001 From: tnaroska Date: Fri, 1 Mar 2013 16:47:12 +0100 Subject: [PATCH] [KARAF-2215] kar fails to attach artifact - additional integration-tests - archetype uses kar-packaging again --- .../src/main/resources/archetype-resources/pom.xml | 2 +- .../src/it/test-kar-classifier/pom.xml | 55 +++++++++++++ .../src/it/test-kar-classifier/verify.bsh | 30 ++++++++ .../src/it/test-kar-multiple-kars/pom.xml | 81 ++++++++++++++++++++ .../src/it/test-kar-multiple-kars/verify.bsh | 35 +++++++++ .../src/it/test-kar-packaging/pom.xml | 39 ++++++++++ .../src/it/test-kar-packaging/verify.bsh | 30 ++++++++ .../src/it/test-kar-with-pom-packaging/pom.xml | 52 +++++++++++++ .../src/it/test-kar-with-pom-packaging/verify.bsh | 30 ++++++++ .../karaf/tooling/features/CreateKarMojo.java | 36 ++++++++- 10 files changed, 386 insertions(+), 4 deletions(-) create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-classifier/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-classifier/verify.bsh create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/verify.bsh create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-packaging/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-packaging/verify.bsh create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/pom.xml create mode 100644 tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/verify.bsh diff --git a/archetypes/kar/src/main/resources/archetype-resources/pom.xml b/archetypes/kar/src/main/resources/archetype-resources/pom.xml index 4dc7827..bd5b73e 100644 --- a/archetypes/kar/src/main/resources/archetype-resources/pom.xml +++ b/archetypes/kar/src/main/resources/archetype-resources/pom.xml @@ -23,7 +23,7 @@ ${groupId} ${artifactId} ${version} - pom + kar ${artifactId}-kar ${artifactId} details diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-classifier/pom.xml b/tooling/karaf-maven-plugin/src/it/test-kar-classifier/pom.xml new file mode 100644 index 0000000..20b2f3a --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-classifier/pom.xml @@ -0,0 +1,55 @@ + + + + 4.0.0 + + test + test-kar-classifier + 1.0-SNAPSHOT + pom + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + + + generate-features-file + + features-generate-descriptor + + + + features-create-kar + + features-create-kar + + + classy + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-classifier/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-kar-classifier/verify.bsh new file mode 100644 index 0000000..be03fa8 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-classifier/verify.bsh @@ -0,0 +1,30 @@ +/* + * 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.*; +import java.lang.*; + + +// check the kar archive was pushed to the repository +File generated = new File( localRepositoryPath, "test/test-kar-classifier/1.0-SNAPSHOT/test-kar-classifier-1.0-SNAPSHOT-classy.kar" ); +if (generated.exists()) { + return true; +} + +return false; diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/pom.xml b/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/pom.xml new file mode 100644 index 0000000..3dd6575 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + test + test-kar-multiple-kars + 1.0-SNAPSHOT + pom + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + + + generate-features-file1 + + features-generate-descriptor + + + feature1 + ${project.build.directory}/feature/feature1.xml + + + + generate-features-file2 + + features-generate-descriptor + + + feature2 + ${project.build.directory}/feature/feature2.xml + + + + + features-create-kar1 + + features-create-kar + + + kar1 + ${project.build.directory}/feature/feature2.xml + + + + features-create-kar2 + + features-create-kar + + + kar2 + ${project.build.directory}/feature/feature2.xml + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/verify.bsh new file mode 100644 index 0000000..926a64a --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-multiple-kars/verify.bsh @@ -0,0 +1,35 @@ +/* + * 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.*; +import java.lang.*; + + +// check the kar archives and feature xmls were pushed to the repository +File feature1 = new File( localRepositoryPath, "test/test-kar-multiple-kars/1.0-SNAPSHOT/test-kar-multiple-kars-1.0-SNAPSHOT-feature1.xml" ); +File feature2 = new File( localRepositoryPath, "test/test-kar-multiple-kars/1.0-SNAPSHOT/test-kar-multiple-kars-1.0-SNAPSHOT-feature2.xml" ); + +File kar1 = new File( localRepositoryPath, "test/test-kar-multiple-kars/1.0-SNAPSHOT/test-kar-multiple-kars-1.0-SNAPSHOT-kar1.kar" ); +File kar2 = new File( localRepositoryPath, "test/test-kar-multiple-kars/1.0-SNAPSHOT/test-kar-multiple-kars-1.0-SNAPSHOT-kar2.kar" ); + +if (feature1.exists() && feature2.exists() && kar1.exists() && kar2.exists()) { + return true; +} + +return false; diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-packaging/pom.xml b/tooling/karaf-maven-plugin/src/it/test-kar-packaging/pom.xml new file mode 100644 index 0000000..a430b48 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-packaging/pom.xml @@ -0,0 +1,39 @@ + + + + 4.0.0 + + test + test-kar-packaging + 1.0-SNAPSHOT + kar + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + true + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-packaging/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-kar-packaging/verify.bsh new file mode 100644 index 0000000..39d99da --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-packaging/verify.bsh @@ -0,0 +1,30 @@ +/* + * 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.*; +import java.lang.*; + + +// check the kar archive was pushed to the repository +File generated = new File( localRepositoryPath, "test/test-kar-packaging/1.0-SNAPSHOT/test-kar-packaging-1.0-SNAPSHOT.kar" ); +if (generated.exists()) { + return true; +} + +return false; diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/pom.xml b/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/pom.xml new file mode 100644 index 0000000..2b12638 --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/pom.xml @@ -0,0 +1,52 @@ + + + + 4.0.0 + + test + test-kar-with-pom-packaging + 1.0-SNAPSHOT + pom + + + + + org.apache.karaf.tooling + karaf-maven-plugin + @pom.version@ + + + generate-features-file + + features-generate-descriptor + + + + features-create-kar + + features-create-kar + + + + + + + diff --git a/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/verify.bsh b/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/verify.bsh new file mode 100644 index 0000000..bbc4f4c --- /dev/null +++ b/tooling/karaf-maven-plugin/src/it/test-kar-with-pom-packaging/verify.bsh @@ -0,0 +1,30 @@ +/* + * 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.*; +import java.lang.*; + + +// check the kar archive was pushed to the repository +File generated = new File( localRepositoryPath, "test/test-kar-with-pom-packaging/1.0-SNAPSHOT/test-kar-with-pom-packaging-1.0-SNAPSHOT.kar" ); +if (generated.exists()) { + return true; +} + +return false; diff --git a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java index 63bc2b6..4f5a6c9 100644 --- a/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java +++ b/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/CreateKarMojo.java @@ -18,7 +18,11 @@ */ package org.apache.karaf.tooling.features; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.InputStream; +import java.io.Writer; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -90,6 +94,14 @@ public class CreateKarMojo extends MojoSupport { private String finalName = null; /** + * Classifier to add to the artifact generated. If given, the artifact will be attached. + * If this is not given,it will merely be written to the output directory according to the finalName. + * + * @parameter + */ + protected String classifier; + + /** * Location of resources directory for additional content to include in the kar. * Note that it includes everything under classes so as to include maven-remote-resources * @@ -123,8 +135,26 @@ public class CreateKarMojo extends MojoSupport { // Build the archive File archive = createArchive(resources); + // backward compatibility HACK + // if no classifier specified and packaging is not kar, emit a warning and attach artifact + if (classifier == null && !"kar".equals(getProject().getPackaging())) + { + getLog().warn("COMPAT MODE: Please update your project to use \"kar\" packaging or configure a \"classifier\" for kar attachment"); + + projectHelper.attachArtifact(getProject(), "kar", null, archive); + return; + } + + // Attach the generated archive for install/deploy - projectHelper.attachArtifact(project, "kar", null, archive); + if (classifier != null) + { + projectHelper.attachArtifact(getProject(), "kar", classifier, archive); + } + else + { + getProject().getArtifact().setFile(archive); + } } /** @@ -167,7 +197,7 @@ public class CreateKarMojo extends MojoSupport { */ private File createArchive(List bundles) throws MojoExecutionException { ArtifactRepositoryLayout layout = new DefaultRepositoryLayout(); - File archiveFile = getArchiveFile(outputDirectory, finalName, null); + File archiveFile = getArchiveFile(outputDirectory, finalName, classifier); MavenArchiver archiver = new MavenArchiver(); archiver.setArchiver(jarArchiver); -- 1.7.10.2 (Apple Git-33)