You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ss...@apache.org on 2016/11/11 21:55:20 UTC
svn commit: r1769351 - in /sling/trunk/tooling/bnd/models-bnd-plugin: ./
src/main/java/org/apache/sling/bnd/models/ src/test/ src/test/java/
src/test/java/dummy/ src/test/java/dummy/example/
src/test/java/dummy/example/pkg1/ src/test/java/dummy/example...
Author: sseifert
Date: Fri Nov 11 21:55:19 2016
New Revision: 1769351
URL: http://svn.apache.org/viewvc?rev=1769351&view=rev
Log:
SLING-6048 add parameter to generate Sling-Model-Packages instead of Sling-Model-Classes header, and a check for maxlength of header value
Added:
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java (with props)
sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java (with props)
Modified:
sling/trunk/tooling/bnd/models-bnd-plugin/pom.xml
sling/trunk/tooling/bnd/models-bnd-plugin/src/main/java/org/apache/sling/bnd/models/ModelsScannerPlugin.java
Modified: sling/trunk/tooling/bnd/models-bnd-plugin/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/pom.xml?rev=1769351&r1=1769350&r2=1769351&view=diff
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/pom.xml (original)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/pom.xml Fri Nov 11 21:55:19 2016
@@ -51,6 +51,28 @@
<version>3.3.2</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.2.15</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.models.api</artifactId>
+ <version>1.3.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Modified: sling/trunk/tooling/bnd/models-bnd-plugin/src/main/java/org/apache/sling/bnd/models/ModelsScannerPlugin.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/main/java/org/apache/sling/bnd/models/ModelsScannerPlugin.java?rev=1769351&r1=1769350&r2=1769351&view=diff
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/main/java/org/apache/sling/bnd/models/ModelsScannerPlugin.java (original)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/main/java/org/apache/sling/bnd/models/ModelsScannerPlugin.java Fri Nov 11 21:55:19 2016
@@ -18,11 +18,14 @@
*/
package org.apache.sling.bnd.models;
-import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import aQute.bnd.osgi.Analyzer;
@@ -44,11 +47,18 @@ public class ModelsScannerPlugin impleme
static final String MODELS_PACKAGES_HEADER = "Sling-Model-Packages";
static final String MODELS_CLASSES_HEADER = "Sling-Model-Classes";
+ // max length of manifest header value 65535 bytes (see http://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html)
+ // fall back to packages header when class names string gets too long
+ static final int MODELS_CLASSES_HEADER_MAXLENGTH = 60000;
+
+ static final String PROPERTY_GENERATE_PACKAGES_HEADER = "generatePackagesHeader";
+
private Reporter reporter;
+ private Map<String,String> properties;
@Override
public void setProperties(Map<String, String> map) throws Exception {
- // ignore
+ properties = map;
}
@Override
@@ -67,7 +77,12 @@ public class ModelsScannerPlugin impleme
// set bundle header containing all class names found
if (!classNames.isEmpty()) {
- analyzer.set(MODELS_CLASSES_HEADER, StringUtils.join(classNames, ","));
+ if (getBooleanProperty(PROPERTY_GENERATE_PACKAGES_HEADER)) {
+ generatePackagesHeader(analyzer, classNames);
+ }
+ else {
+ generateClassesHeader(analyzer, classNames);
+ }
}
}
@@ -76,6 +91,53 @@ public class ModelsScannerPlugin impleme
return false;
}
+ private void generateClassesHeader(Analyzer analyzer, Collection<String> classNames) {
+ String classNameHeader = StringUtils.join(classNames, ",");
+ if (classNameHeader.length() <= MODELS_CLASSES_HEADER_MAXLENGTH) {
+ analyzer.set(MODELS_CLASSES_HEADER, classNameHeader);
+ }
+ else {
+ generatePackagesHeader(analyzer, classNames);
+ }
+ }
+
+ private void generatePackagesHeader(Analyzer analyzer, Collection<String> classNames) {
+
+ // get all package names
+ SortedSet<String> packages = new TreeSet<>();
+ for (String className : classNames) {
+ if (StringUtils.contains(className, ".")) {
+ packages.add(StringUtils.substringBeforeLast(className, "."));
+ }
+ }
+
+ // eliminate package names for which parent packages exist (they are included automatically)
+ Set<String> packagesToRemove = new HashSet<>();
+ for (String packageName : packages) {
+ if (includesParentPackage(packages, packageName)) {
+ packagesToRemove.add(packageName);
+ }
+ }
+ packages.removeAll(packagesToRemove);
+
+ analyzer.set(MODELS_PACKAGES_HEADER, StringUtils.join(packages, ","));
+ }
+
+ private boolean includesParentPackage(Set<String> packages, String packageName) {
+ if (StringUtils.contains(packageName, ".")) {
+ String parentPackageName = StringUtils.substringBeforeLast(packageName, ".");
+ if (packages.contains(parentPackageName)) {
+ return true;
+ }
+ else {
+ return includesParentPackage(packages, parentPackageName);
+ }
+ }
+ else {
+ return false;
+ }
+ }
+
/**
* Get all classes that implement the given annotation via bnd Analyzer.
* @param analyzer Analyzer
@@ -83,12 +145,12 @@ public class ModelsScannerPlugin impleme
* @return Class names
*/
private Collection<String> getClassesWithAnnotation(String annotationClassName, Analyzer analyzer) {
- List<String> classNames = new ArrayList<>();
+ SortedSet<String> classNames = new TreeSet<>();
Collection<Clazz> clazzes = analyzer.getClassspace().values();
Instruction instruction = new Instruction(annotationClassName);
try {
for (Clazz clazz : clazzes) {
- if (clazz.isAnnotation() && clazz.is(QUERY.ANNOTATED, instruction, analyzer)) {
+ if (clazz.is(QUERY.ANNOTATED, instruction, analyzer)) {
classNames.add(clazz.getClassName().getFQN());
}
}
@@ -99,4 +161,9 @@ public class ModelsScannerPlugin impleme
return classNames;
}
+ private boolean getBooleanProperty(String propertyName) {
+ String value = properties != null ? properties.get(propertyName) : null;
+ return BooleanUtils.toBoolean(value);
+ }
+
}
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,26 @@
+/*
+ * 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 dummy.example.pkg1;
+
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables=Object.class)
+public class Model1 {
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model1.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,26 @@
+/*
+ * 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 dummy.example.pkg1;
+
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables=Object.class)
+public class Model2 {
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/Model2.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,26 @@
+/*
+ * 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 dummy.example.pkg1.sub1;
+
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables=Object.class)
+public class Model3 {
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg1/sub1/Model3.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,26 @@
+/*
+ * 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 dummy.example.pkg2;
+
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables=Object.class)
+public class Model4 {
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model4.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,26 @@
+/*
+ * 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 dummy.example.pkg2;
+
+import org.apache.sling.models.annotations.Model;
+
+@Model(adaptables=Object.class)
+public class Model5 {
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/dummy/example/pkg2/Model5.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,89 @@
+/*
+ * 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.sling.bnd.models;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.Manifest;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import aQute.bnd.osgi.Builder;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.service.Plugin;
+import aQute.service.reporter.Reporter;
+
+@RunWith(MockitoJUnitRunner.class)
+public abstract class AbstractModelsScannerPluginTest {
+
+ protected Builder builder;
+
+ @Before
+ public final void setUp() throws Exception {
+ builder = new Builder();
+
+ Jar classesDirJar = new Jar("test.jar", new File("target/test-classes"));
+ classesDirJar.setManifest(new Manifest());
+ builder.setJar(classesDirJar);
+
+ builder.setSourcepath(new File[] { new File("src/test/java") } );
+
+ Plugin plugin = new ModelsScannerPlugin();
+ plugin.setReporter(mock(Reporter.class));
+ plugin.setProperties(getProperties());
+ builder.addBasicPlugin(plugin);
+ }
+
+ @After
+ public final void tearDown() throws Exception {
+ if (!builder.getErrors().isEmpty()) {
+ fail(StringUtils.join(builder.getErrors(), "\n"));
+ }
+ builder.close();
+ }
+
+ protected Map<String,String> getProperties() {
+ return new HashMap<>();
+ }
+
+ protected final void assertHeaderMissing(Jar jar, String headerName) throws Exception {
+ assertNull(jar.getManifest().getMainAttributes().getValue(headerName));
+ }
+
+ protected final void assertHeader(Jar jar, String headerName, String... headerValues) throws Exception {
+ Set<String> expectedValues = new HashSet<>(Arrays.asList(headerValues));
+ String[] actual = StringUtils.split(jar.getManifest().getMainAttributes().getValue(headerName), ",");
+ Set<String> actualValues = new HashSet<>(Arrays.asList(actual));
+ assertEquals(expectedValues, actualValues);
+ }
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/AbstractModelsScannerPluginTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,44 @@
+/*
+ * 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.sling.bnd.models;
+
+import static org.apache.sling.bnd.models.ModelsScannerPlugin.MODELS_CLASSES_HEADER;
+import static org.apache.sling.bnd.models.ModelsScannerPlugin.*;
+
+import org.junit.Test;
+
+import aQute.bnd.osgi.Jar;
+
+public class GenerateClassesHeaderTest extends AbstractModelsScannerPluginTest {
+
+ @Test
+ public void testBuild() throws Exception {
+ Jar jar = builder.build();
+
+ assertHeaderMissing(jar, MODELS_PACKAGES_HEADER);
+
+ assertHeader(jar, MODELS_CLASSES_HEADER,
+ "dummy.example.pkg1.Model1",
+ "dummy.example.pkg1.Model2",
+ "dummy.example.pkg1.sub1.Model3",
+ "dummy.example.pkg2.Model4",
+ "dummy.example.pkg2.Model5");
+ }
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GenerateClassesHeaderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java?rev=1769351&view=auto
==============================================================================
--- sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java (added)
+++ sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java Fri Nov 11 21:55:19 2016
@@ -0,0 +1,53 @@
+/*
+ * 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.sling.bnd.models;
+
+import static org.apache.sling.bnd.models.ModelsScannerPlugin.MODELS_CLASSES_HEADER;
+import static org.apache.sling.bnd.models.ModelsScannerPlugin.MODELS_PACKAGES_HEADER;
+import static org.apache.sling.bnd.models.ModelsScannerPlugin.PROPERTY_GENERATE_PACKAGES_HEADER;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+import aQute.bnd.osgi.Jar;
+
+public class GeneratePackagesHeaderTest extends AbstractModelsScannerPluginTest {
+
+ @Override
+ protected Map<String, String> getProperties() {
+ Map<String,String> props = new HashMap<>();
+ props.put(PROPERTY_GENERATE_PACKAGES_HEADER, "true");
+ return props;
+ }
+
+ @Test
+ public void testBuild() throws Exception {
+ Jar jar = builder.build();
+
+ assertHeader(jar, MODELS_PACKAGES_HEADER,
+ "dummy.example.pkg1",
+ "dummy.example.pkg2");
+
+ assertHeaderMissing(jar, MODELS_CLASSES_HEADER);
+
+ }
+
+}
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Nov 11 21:55:19 2016
@@ -0,0 +1 @@
+LastChangedDate LastChangedRevision LastChangedBy HeadURL Id Author
Propchange: sling/trunk/tooling/bnd/models-bnd-plugin/src/test/java/org/apache/sling/bnd/models/GeneratePackagesHeaderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain