plexus-component-metadata-1.0~beta3.0.7/0000755000175000017500000000000011226720062020024 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/README.txt0000644000175000017500000000040210777725005021532 0ustar twernertwernerThe org.codehaus.plexus.component.repository.cdc package contains some classes copied from the container before it started using the "default" role hints. This can be removed once all supported maven versions are using a container newer than 1.0-alpha-19. plexus-component-metadata-1.0~beta3.0.7/src/0000755000175000017500000000000011226720062020613 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/0000755000175000017500000000000011226720062021227 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/0000755000175000017500000000000011226720062023543 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/validate.groovy0000644000175000017500000000161411202346122026600 0ustar twernertwerner/* * Copyright (C) 2006-2007 the original author or authors. * * Licensed 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. */ // // $Id: validate.groovy 8178 2009-05-12 19:21:54Z bentmann $ // def file = new File(basedir, 'target/classes/META-INF/plexus/components.xml') assert file.exists() def componentSet = new XmlParser().parse(file) assert componentSet.components.component.size() == 2 return true; plexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/0000755000175000017500000000000011226720062024332 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/0000755000175000017500000000000011226720062025256 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/java/0000755000175000017500000000000011226720062026177 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/java/testing/0000755000175000017500000000000011226720062027654 5ustar twernertwerner././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/java/testing/ChildComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/java/testing/ChildComponent.jav0000644000175000017500000000152310700072732033265 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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 testing; import org.codehaus.plexus.component.annotations.*; /** * ??? * * @version $Id: ChildComponent.java 6922 2007-10-01 04:21:46Z user57 $ */ @Component(role=ChildComponent.class) public class ChildComponent { } plexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/src/main/java/testing/MyComponent.java0000644000175000017500000000170110700072732032766 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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 testing; import org.codehaus.plexus.component.annotations.*; /** * ??? * * @version $Id: MyComponent.java 6922 2007-10-01 04:21:46Z user57 $ */ @Component(role=MyComponent.class, hint="foo") public class MyComponent { @Requirement private ChildComponent child; @Configuration("bar") private String foo; } plexus-component-metadata-1.0~beta3.0.7/src/it/descriptor-1/pom.xml0000644000175000017500000000430111202346122025051 0ustar twernertwerner 4.0.0 org.codehaus.plexus.it.plexus-cdc-anno descriptor-1 testing org.codehaus.plexus plexus-component-annotations @project.version@ org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-component-metadata-1.0~beta3.0.7/src/it/settings.xml0000644000175000017500000000157611202346122023615 0ustar twernertwerner it-repo true local.central @localRepositoryUrl@ true true local.central @localRepositoryUrl@ true true plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/0000755000175000017500000000000011226720062024313 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/0000755000175000017500000000000011226720062025560 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/0000755000175000017500000000000011226720062026347 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/main/0000755000175000017500000000000011226720062027273 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/main/java/0000755000175000017500000000000011226720062030214 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/main/java/test/0000755000175000017500000000000011226720062031173 5ustar twernertwerner././@LongLink0000000000000000000000000000015100000000000011562 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/main/java/test/Component.javaplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/src/main/java/test/Component.0000644000175000017500000000031611125010723033130 0ustar twernertwernerpackage test; // NOTE: This source file is by design encoded using ISO-8859-1! /** * TEST-CHARS: * * @plexus.component role="test.Component" role-hint="default" */ public class Component { } plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/latin-1/pom.xml0000644000175000017500000000255111202346122027073 0ustar twernertwerner 4.0.0 org.codehaus.plexus.its.metadata latin-1 1.0 Latin-1 Test that source files using Latin-1 are properly parsed. ISO-8859-1 org.apache.maven.plugins maven-compiler-plugin 2.0.2 org.apache.maven.plugins maven-resources-plugin 2.2 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/validate.groovy0000644000175000017500000000116511202346122027351 0ustar twernertwernerdef latin1File = new File(basedir, 'latin-1/target/classes/META-INF/plexus/components.xml') assert latin1File.exists() def latin1Chars = new XmlParser().parse(latin1File).components.component.description.text() println latin1Chars assert "TEST-CHARS: \u00C4\u00D6\u00DC\u00E4\u00F6\u00FC\u00DF".equals( latin1Chars ) def utf8File = new File(basedir, 'utf-8/target/classes/META-INF/plexus/components.xml') assert utf8File.exists() def utf8Chars = new XmlParser().parse(utf8File).components.component.description.text() println utf8Chars assert "TEST-CHARS: \u00DF\u0131\u03A3\u042F\u05D0\u20AC".equals( utf8Chars ) return true; plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/0000755000175000017500000000000011226720062025256 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/0000755000175000017500000000000011226720062026045 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/main/0000755000175000017500000000000011226720062026771 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/main/java/0000755000175000017500000000000011226720062027712 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/main/java/test/0000755000175000017500000000000011226720062030671 5ustar twernertwerner././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/main/java/test/Component.javaplexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/src/main/java/test/Component.ja0000644000175000017500000000031711125010723033142 0ustar twernertwernerpackage test; // NOTE: This source file is by design encoded using UTF-8! /** * TEST-CHARS: ßıΣЯא€ * * @plexus.component role="test.Component" role-hint="default" */ public class Component { } plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/utf-8/pom.xml0000644000175000017500000000253611202346122026574 0ustar twernertwerner 4.0.0 org.codehaus.plexus.its.metadata utf-8 1.0 UTF-8 Test that source files using UTF-8 are properly parsed. UTF-8 org.apache.maven.plugins maven-compiler-plugin 2.0.2 org.apache.maven.plugins maven-resources-plugin 2.2 org.codehaus.plexus plexus-component-metadata @project.version@ generate-metadata plexus-component-metadata-1.0~beta3.0.7/src/it/source-encoding/pom.xml0000644000175000017500000000124511125010723025624 0ustar twernertwerner 4.0.0 org.codehaus.plexus.its.metadata aggregator 1.0 pom Aggregator Test that the character encoding of source files is respected by the metadata extractor. utf-8 latin-1 plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/0000755000175000017500000000000011226720062026530 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/0000755000175000017500000000000011226720062027317 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/0000755000175000017500000000000011226720062030276 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/0000755000175000017500000000000011226720062031217 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/0000755000175000017500000000000011226720062032006 5ustar twernertwerner././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus/plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus0000755000175000017500000000000011226720062033522 5ustar twernertwerner././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus/plexus/plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus0000755000175000017500000000000011226720062033522 5ustar twernertwerner././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus/plexus/AppTest.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/test/java/org/codehaus0000644000175000017500000000120711144320355033524 0ustar twernertwernerpackage org.codehaus.plexus; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } } plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/0000755000175000017500000000000011226720062030243 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/0000755000175000017500000000000011226720062031164 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/0000755000175000017500000000000011226720062031753 5ustar twernertwerner././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000755000175000017500000000000011226720062033467 5ustar twernertwerner././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000755000175000017500000000000011226720062033467 5ustar twernertwerner././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/SlowExecutor.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000040411144320355033467 0ustar twernertwernerpackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role=Executor.class,hint="slow") public class SlowExecutor implements Executor { public String execute() { return "slow"; } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/Executor.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000012211144320355033464 0ustar twernertwernerpackage org.codehaus.plexus; public interface Executor { String execute(); } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/PlexusComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000013111144320355033464 0ustar twernertwernerpackage org.codehaus.plexus; public interface PlexusComponent { String execute(); } ././@LongLink0000000000000000000000000000021100000000000011557 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/SubclassPlexusComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000042611144320355033473 0ustar twernertwernerpackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role = Component.class) public class SubclassPlexusComponent extends AbstractPlexusComponent { public String execute() { return executor.execute(); } } ././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/FastExecutor.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000040111144320355033464 0ustar twernertwernerpackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Component; @Component(role = Executor.class, hint = "fast") public class FastExecutor implements Executor { public String execute() { return "fast"; } } ././@LongLink0000000000000000000000000000021100000000000011557 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus/plexus/AbstractPlexusComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/src/main/java/org/codehaus0000644000175000017500000000034011144320355033466 0ustar twernertwernerpackage org.codehaus.plexus; import org.codehaus.plexus.component.annotations.Requirement; public abstract class AbstractPlexusComponent implements PlexusComponent { @Requirement protected Executor executor; } plexus-component-metadata-1.0~beta3.0.7/src/it/annotation-processing-test/pom.xml0000644000175000017500000000322411144320355030046 0ustar twernertwerner 4.0.0 org.codehaus.plexus annotation-processing-test jar 1.0-SNAPSHOT annotation-processing-test http://maven.apache.org 1.0-beta-3.0.6-SNAPSHOT junit junit 3.8.1 test org.codehaus.plexus plexus-component-annotations ${plexusVersion} org.apache.maven.plugins maven-compiler-plugin 1.5 1.5 org.codehaus.plexus plexus-component-metadata ${plexusVersion} generate-metadata plexus-component-metadata-1.0~beta3.0.7/src/site/0000755000175000017500000000000011226720062021557 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/site/site.xml0000644000175000017500000000042211126637653023257 0ustar twernertwerner plexus-component-metadata-1.0~beta3.0.7/src/test/0000755000175000017500000000000011226720061021571 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/0000755000175000017500000000000011226720061023603 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/0000755000175000017500000000000011226720061024372 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/0000755000175000017500000000000011226720061026165 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/0000755000175000017500000000000011226720061027505 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/0000755000175000017500000000000011226720061031265 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/merge/0000755000175000017500000000000011226720061032364 5ustar twernertwerner././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/merge/recessive.xmlplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/merge/recess0000644000175000017500000000370211054050041033566 0ustar twernertwerner org.codehaus.plexus.metadata.component.IComponent org.codehaus.plexus.metadata.component.RecessiveComponent Description for conflicting recessive component Recessive Property1 value Property3 value org.codehaus.plexus.metadata.component.IComponentA recessiveField org.codehaus.plexus.metadata.component.INonConflictingComponent org.codehaus.plexus.metadata.component.RecessiveComponent Description for non-conflicting recessive component Non conflicting Property1 value Non conflicting Property2 value org.codehaus.plexus.metadata.component.IComponentA webapp webapp Webapp ././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/merge/dominant.xmlplexus-component-metadata-1.0~beta3.0.7/src/test/resources/org/codehaus/plexus/metadata/merge/domina0000644000175000017500000000120011054050041033540 0ustar twernertwerner org.codehaus.plexus.metadata.component.IComponent org.codehaus.plexus.metadata.component.DominantComponent Description for Dominant component Dominant Property1 value Dominant Property2 value org.codehaus.plexus.metadata.component.IComponentA plexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/0000755000175000017500000000000011226720061025434 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/0000755000175000017500000000000011226720061027320 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/0000755000175000017500000000000011226720061030107 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/0000755000175000017500000000000011226720061031033 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/0000755000175000017500000000000011226720061031754 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/0000755000175000017500000000000011226720061032543 5ustar twernertwerner././@LongLink0000000000000000000000000000015300000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/cod0000755000175000017500000000000011226720061033231 5ustar twernertwerner././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/plexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/cod0000755000175000017500000000000011226720061033231 5ustar twernertwerner././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/component/plexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/cod0000755000175000017500000000000011226720061033231 5ustar twernertwerner././@LongLink0000000000000000000000000000020600000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/component/Hello.javaplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/cod0000644000175000017500000000021710565423462033245 0ustar twernertwernerpackage org.codehaus.plexus.component; public interface Hello { final static String ROLE = Hello.class.getName(); void sayHello(); }././@LongLink0000000000000000000000000000021200000000000011560 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/codehaus/plexus/component/HelloImpl.javaplexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/src/main/java/org/cod0000644000175000017500000000052610565423462033250 0ustar twernertwernerpackage org.codehaus.plexus.component; /** * @plexus.component */ public class HelloImpl implements Hello { /** * @plexus.configuration expression="${expression}" default-value="Hello World!" * @required */ private String message; public void sayHello() { System.out.print( message ); } }plexus-component-metadata-1.0~beta3.0.7/src/test/resources/projects/project-01/pom.xml0000644000175000017500000000160610536361003030640 0ustar twernertwerner 4.0.0 plexus-maven-test plexus-maven-plugin-test 0.1 Plexus Maven Plugin Test org.codehaus.plexus plexus-maven-plugin true descriptor plexus-component-metadata-1.0~beta3.0.7/src/test/java/0000755000175000017500000000000011226720060022511 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/0000755000175000017500000000000011226720060023300 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/0000755000175000017500000000000011226720060025073 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/0000755000175000017500000000000011226720060026413 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/0000755000175000017500000000000011226720060030173 5ustar twernertwerner././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriterTest.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/DefaultComponentD0000644000175000017500000000701711175110715033501 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata; import java.io.StringWriter; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.io.PlexusTools; import org.codehaus.plexus.configuration.PlexusConfiguration; /** * Test for the {@link DefaultComponentDescriptorWriter} class. * * @version $Rev: 8157 $ $Date: 2009-04-26 18:54:37 +0200 (So, 26. Apr 2009) $ */ public class DefaultComponentDescriptorWriterTest extends PlexusTestCase { private DefaultComponentDescriptorWriter descriptorWriter; // @Override protected void setUp() throws Exception { super.setUp(); descriptorWriter = (DefaultComponentDescriptorWriter) lookup(ComponentDescriptorWriter.class); assertNotNull(descriptorWriter); } // @Override protected void tearDown() throws Exception { descriptorWriter = null; super.tearDown(); } public void testBasic() throws Exception { ComponentSetDescriptor set = new ComponentSetDescriptor(); ComponentDescriptor component = new ComponentDescriptor(); component.setImplementation("java.lang.String"); component.setRole("foo"); component.setRoleHint("bar"); component.setComponentFactory("baz"); set.addComponentDescriptor(component); StringWriter writer = new StringWriter(); descriptorWriter.writeDescriptorSet(writer, set, false); writer.flush(); writer.close(); String xml = writer.toString(); assertTrue(xml.length() != 0); PlexusConfiguration config = PlexusTools.buildConfiguration(xml); assertNotNull(config); ClassWorld classWorld = new ClassWorld( "test", Thread.currentThread().getContextClassLoader() ); ClassRealm realm = classWorld.getRealm( "test" ); org.codehaus.plexus.component.repository.ComponentSetDescriptor set2 = PlexusTools.buildComponentSet(config, realm); assertNotNull(set2); List components = set2.getComponents(); assertNotNull(components); assertEquals(1, components.size()); org.codehaus.plexus.component.repository.ComponentDescriptor component2 = (org.codehaus.plexus.component.repository.ComponentDescriptor) components.get(0); assertNotNull(component2); assertEquals(component.getRole(), component2.getRole()); assertEquals(component.getRoleHint(), component2.getRoleHint()); assertEquals(component.getComponentFactory(), component2.getComponentFactory()); // // TODO: Verify requirements and configuration too... but I'm too lazy for that right now // } } plexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/0000755000175000017500000000000011226720061031611 5ustar twernertwerner././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/AbstractWithAnnoClass.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/AbstractW0000644000175000017500000000152011056370727033437 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="foo" * * @version $Id: AbstractWithAnnoClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public abstract class AbstractWithAnnoClass { } ././@LongLink0000000000000000000000000000015700000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ChildComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ChildComp0000644000175000017500000000155111056370727033413 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="org.codehaus.plexus.metadata.gleaner.ChildComponent" * * @version $Id: ChildComponent.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public class ChildComponent { } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleanerTest.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/Annotatio0000644000175000017500000000451011144377236033503 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponent; import org.codehaus.plexus.metadata.gleaner.ann.AnnotatedComponentRole; import junit.framework.TestCase; /** * @author Eugene Kuleshov */ public class AnnotationComponentGleanerTest extends TestCase { public void testGlean() throws Exception { AnnotationComponentGleaner gleaner = new AnnotationComponentGleaner(); Class c = AnnotatedComponent.class; ComponentDescriptor descriptor = gleaner.glean(c.getName(), c.getClassLoader()); assertEquals("foo", descriptor.getComponentType()); assertEquals(AnnotatedComponentRole.class.getName(), descriptor.getRole()); List requirements = descriptor.getRequirements(); assertEquals(requirements.toString(), 2, requirements.size()); ComponentRequirement requirement = requirements.get(0); assertEquals("dependency", requirement.getFieldName()); assertEquals("default", requirement.getRoleHint()); ComponentRequirement requirement2 = requirements.get(1); assertEquals("dependency2", requirement2.getFieldName()); assertEquals("release,latest,snapshot", requirement2.getRoleHint()); PlexusConfiguration configuration = descriptor.getConfiguration(); assertEquals(1, configuration.getChildCount()); PlexusConfiguration child = configuration.getChild(0); assertEquals("param", child.getName()); assertEquals("value", child.getValue()); } } ././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/MyComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/MyCompone0000644000175000017500000000204011056370727033451 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @plexus.component role="org.codehaus.plexus.metadata.gleaner.MyComponent" role-hint="foo" * * @version $Rev: 7691 $ $Date: 2008-08-31 03:20:23 +0200 (So, 31. Aug 2008) $ */ public class MyComponent { /** * @plexus.requirement */ private ChildComponent child; /** * @plexus.configuration default-value="bar" */ private String foo; } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/NoAnnotationsIntf.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/NoAnnotat0000644000175000017500000000144011056370727033447 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: NoAnnotationsIntf.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public interface NoAnnotationsIntf { } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/NoAnnotationsClass.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/NoAnnotat0000644000175000017500000000143611056370727033454 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: NoAnnotationsClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public class NoAnnotationsClass { } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/AbstractClass.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/AbstractC0000644000175000017500000000143511056370727033420 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; /** * ??? * * @version $Id: AbstractClass.java 7702 2008-08-31 01:20:23Z jvanzyl $ */ public abstract class AbstractClass { } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleanerTest.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/QDoxCompo0000644000175000017500000001121011107373274033410 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; import java.io.File; import java.io.IOException; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.configuration.PlexusConfiguration; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; /** * Tests for the {@link QDoxComponentGleaner} class. * * @version $Rev: 7828 $ $Date: 2008-11-14 23:07:56 +0100 (Fr, 14. Nov 2008) $ */ public class QDoxComponentGleanerTest extends PlexusTestCase { private QDoxComponentGleaner gleaner; private JavaDocBuilder builder; // @Override protected void setUp() throws Exception { super.setUp(); gleaner = new QDoxComponentGleaner(); builder = new JavaDocBuilder(); } // @Override protected void tearDown() throws Exception { gleaner = null; builder = null; super.tearDown(); } private JavaSource addSource( final String name ) throws IOException { File url = new File( getBasedir(), "src/test/java/" + getClass().getPackage().getName().replace( '.', '/' ) + "/" + name ); assertTrue( url.exists() ); return builder.addSource( url ); } private JavaClass loadJavaClass( final String name ) throws IOException { JavaSource source = addSource( name ); assertNotNull( source ); JavaClass[] classes = source.getClasses(); assertNotNull( classes ); assertEquals( 1, classes.length ); assertNotNull( classes[0] ); return classes[0]; } private ComponentDescriptor glean( final String name, final String[] supporting ) throws Exception { if ( supporting != null ) { for ( String aSupporting : supporting ) { addSource( aSupporting ); } } return gleaner.glean( builder, loadJavaClass( name ) ); } private ComponentDescriptor glean( final String name ) throws Exception { return glean( name, null ); } public void testNoAnnotationsClass() throws Exception { ComponentDescriptor component = glean( "NoAnnotationsClass.java" ); assertNull( component ); } public void testAbstractClass() throws Exception { ComponentDescriptor component = glean( "AbstractClass.java" ); assertNull( component ); } /* public void testAbstractWithAnnoClass() throws Exception { ComponentDescriptor component = glean("AbstractWithAnnoClass.java"); assertNull(component); } */ public void testNoAnnotationsIntf() throws Exception { ComponentDescriptor component = glean( "NoAnnotationsIntf.java" ); assertNull( component ); } public void testMyComponent() throws Exception { addSource( "ChildComponent.java" ); ComponentDescriptor component = glean( "MyComponent.java" ); assertNotNull( component ); assertEquals( MyComponent.class.getName(), component.getRole() ); assertEquals( "foo", component.getRoleHint() ); List requirements = component.getRequirements(); assertNotNull( requirements ); assertEquals( 1, requirements.size() ); ComponentRequirement requirement = requirements.get( 0 ); assertNotNull( requirement ); assertEquals( ChildComponent.class.getName(), requirement.getRole() ); PlexusConfiguration config = component.getConfiguration(); assertNotNull( config ); assertEquals( 1, config.getChildCount() ); PlexusConfiguration child = config.getChild( 0 ); assertNotNull( child ); assertEquals( "foo", child.getName() ); assertEquals( "bar", child.getValue() ); } } plexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/0000755000175000017500000000000011226720061032365 5ustar twernertwerner././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/AnnotatedComponent.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/Annot0000644000175000017500000000244711144377236033411 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner.ann; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Configuration; import org.codehaus.plexus.component.annotations.Requirement; /** * @author Eugene Kuleshov */ @Component(type="foo", role=AnnotatedComponentRole.class) public class AnnotatedComponent implements AnnotatedComponentRole { @Requirement(hint="default") @Configuration(name="param", value="value") AnnotatedComponentDependency dependency; @Requirement(role=AnnotatedComponentDependency.class, hints={"release", "latest", "snapshot"}) List dependency2; } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/AnnotatedComponentRole.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/Annot0000644000175000017500000000131411075233331033367 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner.ann; public interface AnnotatedComponentRole { } ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/AnnotatedComponentDependency.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/gleaner/ann/Annot0000644000175000017500000000136111075233331033371 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner.ann; /** * @author Eugene Kuleshov */ public class AnnotatedComponentDependency { } plexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/merge/0000755000175000017500000000000011226720060031272 5ustar twernertwerner././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/merge/ComponentsXmlMergerTest.javaplexus-component-metadata-1.0~beta3.0.7/src/test/java/org/codehaus/plexus/metadata/merge/ComponentsX0000644000175000017500000003055211107373274033510 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.util.List; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.metadata.merge.support.AbstractMergeableElement; import org.codehaus.plexus.metadata.merge.support.AbstractMergeableElementList; import org.codehaus.plexus.metadata.merge.support.ComponentElement; import org.codehaus.plexus.metadata.merge.support.ComponentsElement; import org.codehaus.plexus.metadata.merge.support.RequirementsElement; import org.codehaus.plexus.util.FileUtils; import org.jdom.Document; import org.jdom.Element; import org.jdom.input.SAXBuilder; /** * Tests for {@link ComponentsXmlMerger}. * * @author Rahul Thakur * @version $Id: ComponentsXmlMergerTest.java 7828 2008-11-14 22:07:56Z dain $ */ public class ComponentsXmlMergerTest extends PlexusTestCase { public void testBasic() throws Exception { ComponentsXmlMerger merger = (ComponentsXmlMerger) lookup( Merger.class, "componentsXml" ); assertNotNull( merger ); } public void testComponentsXmlFileMerge() throws Exception { File dominantXml = getTestFile( "src/test/resources/org/codehaus/plexus/metadata/merge/dominant.xml" ); File recessiveXml = getTestFile( "src/test/resources/org/codehaus/plexus/metadata/merge/recessive.xml" ); Document dDoc = new SAXBuilder().build( dominantXml ); Document rDoc = new SAXBuilder().build( recessiveXml ); // ComponentsXmlMerger merger = new ComponentsXmlMerger (dDoc); Merger merger = lookup( Merger.class, "componentsXml" ); assertNotNull( merger ); merger.merge( dDoc, rDoc ); File merged_xml = getTestFile( "target/merged.xml" ); if ( merged_xml.exists() ) { FileUtils.forceDelete( merged_xml ); } merger.writeMergedDocument( dDoc, merged_xml ); assertTrue( merged_xml.exists() ); // read merged xml and verify it was merged as expected Document mDoc = new SAXBuilder().build( merged_xml ); Element mRootElt = mDoc.getRootElement(); assertTrue( mRootElt.getName().equals( "component-set" ) ); assertEquals( 1, mRootElt.getChildren( "components" ).size() ); List componentEltList = mRootElt.getChild( "components" ).getChildren( "component" ); assertEquals( 2, componentEltList.size() ); Element cElt = (Element) componentEltList.get( 0 ); assertEquals( "org.codehaus.plexus.metadata.component.IComponent", cElt.getChildTextTrim( "role" ) ); assertEquals( "org.codehaus.plexus.metadata.component.DominantComponent", cElt.getChildTextTrim( "implementation" ) ); assertEquals( "Should only have 1 description element.", 1, cElt.getChildren( "description" ).size() ); assertEquals( "Description for Dominant component", cElt.getChildTextTrim( "description" ) ); assertEquals( "Should only have 1 configuration element.", 1, cElt.getChildren( "configuration" ).size() ); // assert Merged configuration properties Element configurationElt = cElt.getChild( "configuration" ); assertNotNull( configurationElt ); assertEquals( 1, configurationElt.getChildren( "prop1" ).size() ); assertEquals( "Dominant Property1 value", configurationElt.getChildTextTrim( "prop1" ) ); assertEquals( 1, configurationElt.getChildren( "prop2" ).size() ); assertEquals( 0, configurationElt.getChildren( "prop3" ).size() ); // now for the second component cElt = (Element) componentEltList.get( 1 ); assertEquals( "org.codehaus.plexus.metadata.component.INonConflictingComponent", cElt.getChildTextTrim( "role" ) ); assertEquals( "org.codehaus.plexus.metadata.component.RecessiveComponent", cElt.getChildTextTrim( "implementation" ) ); assertEquals( 1, mRootElt.getChildren( "lifecycle-handler-manager" ).size() ); assertEquals( "org.codehaus.plexus.lifecycle.DefaultLifecycleHandlerManager", mRootElt .getChild( "lifecycle-handler-manager" ).getAttributeValue( "implementation" ) ); } public void testInvalidMergeableElements() throws Exception { // dominant Component Element AbstractMergeableElement dCE = new ComponentElement( new Element( "component" ) ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); AbstractMergeableElementList reqElt = new RequirementsElement( new Element( "requirement" ) ); // attempt and invalid merge try { dCE.merge( reqElt ); fail( "Expected MergeException!" ); } catch ( MergeException e ) { // do nothing. } } /** * Tests if <component> elements from two sets are being merged properly. * * @throws Exception if there was an unexpected error. */ public void testComponentsMerge() throws Exception { // dominant Components Element AbstractMergeableElement dParent = new ComponentsElement( new Element( "components" ) ); Element dCE = new Element( "component" ); dParent.addContent( dCE ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); Element roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "sample-role-hint" ); dCE.addContent( roleHintElt ); Element implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.DominantImplementation" ); dCE.addContent( implElt ); Element requirementsElt = new Element( "requirements" ); Element reqElt = new Element( "requirement" ); Element reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); dCE.addContent( requirementsElt ); // recessive Component Element AbstractMergeableElement rParent = new ComponentsElement( new Element( "components" ) ); Element rCE = new Element( "component" ); rParent.addContent( rCE ); roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); rCE.addContent( roleElt ); roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "sample-role-hint" ); rCE.addContent( roleHintElt ); implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.RecessiveImplementation" ); rCE.addContent( implElt ); Element lifecycleHandlerElt = new Element( "lifecycle-handler" ); rCE.addContent( lifecycleHandlerElt ); lifecycleHandlerElt.setText( "plexus-configurable" ); requirementsElt = new Element( "requirements" ); reqElt = new Element( "requirement" ); reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); Element reqRoleHintElt = new Element( "role-hint" ); reqRoleHintElt.setText( "recessive-required-role-hint" ); reqElt.addContent( reqRoleHintElt ); rCE.addContent( requirementsElt ); // attempt to merge dParent.merge( rParent ); assertEquals( 1, dParent.getChildren( "component" ).size() ); assertEquals( "org.codehaus.plexus.DominantImplementation", dParent.getChild( "component" ) .getChildText( "implementation" ) ); assertEquals( 1, dParent.getChild( "component" ).getChild( "requirements" ).getChildren( "requirement" ).size() ); } /** * This is deprecated as we dont' want to drill to merging * nested elements within a component.

* Keeping this around for testing MergeStrategy implmentation. * * @throws Exception */ public void testDeepComponentsMerge() throws Exception { // FIXME: Review this after MergeStrategies are in place. if ( true ) { return; } // dominant Component Element AbstractMergeableElement dCE = new ComponentElement( new Element( "component" ) ); Element roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); dCE.addContent( roleElt ); Element roleHintElt; // roleHintElt = new Element ("role-hint"); // roleHintElt.setText ("sample-hint"); // dCE.addContent (roleHintElt); Element implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.DominantImplementation" ); dCE.addContent( implElt ); Element requirementsElt = new Element( "requirements" ); Element reqElt = new Element( "requirement" ); Element reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); dCE.addContent( requirementsElt ); // recessive Component Element AbstractMergeableElement rCE = new ComponentElement( new Element( "component" ) ); roleElt = new Element( "role" ); roleElt.setText( "org.codehaus.plexus.ISampleRole" ); rCE.addContent( roleElt ); roleHintElt = new Element( "role-hint" ); roleHintElt.setText( "recessive-hint" ); rCE.addContent( roleHintElt ); implElt = new Element( "implementation" ); implElt.setText( "org.codehaus.plexus.RecessiveImplementation" ); rCE.addContent( implElt ); Element lifecycleHandlerElt = new Element( "lifecycle-handler" ); rCE.addContent( lifecycleHandlerElt ); lifecycleHandlerElt.setText( "plexus-configurable" ); requirementsElt = new Element( "requirements" ); reqElt = new Element( "requirement" ); reqRoleElt = new Element( "role" ); reqRoleElt.setText( "org.codehaus.plexus.IRequiredRole" ); reqElt.addContent( reqRoleElt ); requirementsElt.addContent( reqElt ); Element reqRoleHintElt = new Element( "role-hint" ); reqRoleHintElt.setText( "recessive-required-role-hint" ); reqElt.addContent( reqRoleHintElt ); rCE.addContent( requirementsElt ); // attempt to merge dCE.merge( rCE ); // verify the merge assertTrue( null != dCE.getChild( "role" ) ); assertEquals( "org.codehaus.plexus.ISampleRole", dCE.getChildText( "role" ) ); assertTrue( null != dCE.getChild( "role-hint" ) ); assertEquals( "recessive-hint", dCE.getChildText( "role-hint" ) ); assertTrue( null != dCE.getChild( "lifecycle-handler" ) ); assertEquals( "plexus-configurable", dCE.getChildText( "lifecycle-handler" ) ); assertTrue( null != dCE.getChild( "requirements" ) ); assertEquals( 1, dCE.getChild( "requirements" ).getChildren( "requirement" ).size() ); assertEquals( "recessive-required-role-hint", ( (Element) dCE.getChild( "requirements" ) .getChildren( "requirement" ).get( 0 ) ).getChildText( "role-hint" ) ); } } plexus-component-metadata-1.0~beta3.0.7/src/test/sources/0000755000175000017500000000000011226720061023254 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/test/sources/Empty.java0000644000175000017500000000003010777433450025223 0ustar twernertwerner/* No class in here */ plexus-component-metadata-1.0~beta3.0.7/src/test/sources/Component.java0000644000175000017500000000007110777433450026074 0ustar twernertwerner/** * @plexus.component */ public class Component { } plexus-component-metadata-1.0~beta3.0.7/src/main/0000755000175000017500000000000011226720062021537 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/resources/0000755000175000017500000000000011226720062023551 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/resources/META-INF/0000755000175000017500000000000011226720062024711 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/resources/META-INF/plexus/0000755000175000017500000000000011226720062026231 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/resources/META-INF/plexus/components.xml0000644000175000017500000000362011114626430031141 0ustar twernertwerner org.codehaus.plexus.metadata.gleaner.SourceComponentGleaner qdox org.codehaus.plexus.metadata.gleaner.QDoxComponentGleaner org.codehaus.plexus.metadata.ComponentDescriptorCreator org.codehaus.plexus.metadata.DefaultComponentDescriptorCreator org.codehaus.plexus.metadata.ComponentDescriptorWriter org.codehaus.plexus.metadata.DefaultComponentDescriptorWriter org.codehaus.plexus.metadata.merge.Merger componentsXml org.codehaus.plexus.metadata.merge.ComponentsXmlMerger org.codehaus.plexus.metadata.merge.Merger plexusXml org.codehaus.plexus.metadata.merge.PlexusXmlMerger org.codehaus.plexus.metadata.gleaner.ClassComponentGleaner annotation org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner org.codehaus.plexus.metadata.MetadataGenerator org.codehaus.plexus.metadata.DefaultMetadataGenerator org.codehaus.plexus.metadata.merge.Merger componentsXml plexus-component-metadata-1.0~beta3.0.7/src/main/java/0000755000175000017500000000000011226720061022457 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/0000755000175000017500000000000011226720061023246 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/0000755000175000017500000000000011226720061025041 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/0000755000175000017500000000000011226720062026362 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/0000755000175000017500000000000011226720062030142 5ustar twernertwerner././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescriptorWriter.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescript0000644000175000017500000000311411054050041033514 0ustar twernertwerner/* * The MIT License * * Copyright (c) 2007, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package org.codehaus.plexus.metadata; import java.io.IOException; import java.io.Writer; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; /** * @author Kenney Westerhof */ public interface ComponentDescriptorWriter { void writeDescriptorSet( Writer writer, ComponentSetDescriptor componentSetDescriptor, boolean containerDescriptor ) throws ComponentDescriptorWriteException, IOException; } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/MetadataGenerationRequest.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/MetadataGeneratio0000644000175000017500000000245011125010723033436 0ustar twernertwernerpackage org.codehaus.plexus.metadata; import java.io.File; import java.util.List; public class MetadataGenerationRequest { /** Source to examine for Javadoc annotions which are used to generate component metadata. */ public List sourceDirectories; //todo: these should be files /** The character encoding of the source files, may be {@code null} or empty to use platform's default encoding. */ public String sourceEncoding; /** Classes to examine for annotations which are used to generate component metadata. */ public File classesDirectory; /** Supporting classpath required by class-based annotation processing. */ public List classpath; //todo: these should be files /** Flag to indicate using the context classloader for the supporting classpath required by annotation-based processing. */ public boolean useContextClassLoader; /** Directory where existing component descriptors live. */ public File componentDescriptorDirectory; /** Existing component descriptors that need to be merged. */ public List componentDescriptors; /** Where existing component descriptors are merged. */ public File intermediaryFile; /** Output file for the final component descriptor. */ public File outputFile; } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/0000755000175000017500000000000011226720062031557 5ustar twernertwerner././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxComponentGleaner.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/QDoxCompo0000644000175000017500000004657311124722742033376 0ustar twernertwernerpackage org.codehaus.plexus.metadata.gleaner; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable; import org.codehaus.plexus.util.StringUtils; import com.thoughtworks.qdox.model.DocletTag; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaClassCache; import com.thoughtworks.qdox.model.JavaField; /** * A source component gleaner which uses QDox to discover Javadoc annotations. * * @author Trygve Laugstøl * @version $Id: QDoxComponentGleaner.java 7966 2008-12-25 15:25:22Z bentmann $ */ public class QDoxComponentGleaner extends ComponentGleanerSupport implements SourceComponentGleaner { public static final String PLEXUS_COMPONENT_TAG = "plexus.component"; public static final String PLEXUS_REQUIREMENT_TAG = "plexus.requirement"; public static final String PLEXUS_CONFIGURATION_TAG = "plexus.configuration"; public static final String PLEXUS_VERSION_PARAMETER = "version"; public static final String PLEXUS_ROLE_PARAMETER = "role"; public static final String PLEXUS_ROLE_HINT_PARAMETER = "role-hint"; public static final String PLEXUS_ROLE_HINT_LIST_PARAMETER = "role-hints"; public static final String PLEXUS_ALIAS_PARAMETER = "alias"; public static final String PLEXUS_DEFAULT_VALUE_PARAMETER = "default-value"; public static final String PLEXUS_LIFECYCLE_HANDLER_PARAMETER = "lifecycle-handler"; public static final String PLEXUS_INSTANTIATION_STARTEGY_PARAMETER = "instantiation-strategy"; public static final String PLEXUS_DEFAULT_HINT = "default"; // ---------------------------------------------------------------------- // ComponentGleaner Implementation // ---------------------------------------------------------------------- public ComponentDescriptor glean( JavaClassCache classCache, JavaClass javaClass ) throws ComponentGleanerException { DocletTag tag = javaClass.getTagByName( PLEXUS_COMPONENT_TAG ); if ( tag == null ) { return null; } Map parameters = tag.getNamedParameterMap(); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- String fqn = javaClass.getFullyQualifiedName(); //log.debug( "Creating descriptor for component: {}", fqn ); ComponentDescriptor componentDescriptor = new ComponentDescriptor(); componentDescriptor.setImplementation( fqn ); // ---------------------------------------------------------------------- // Role // ---------------------------------------------------------------------- String role = getParameter( parameters, PLEXUS_ROLE_PARAMETER ); if ( role == null ) { role = findRole( javaClass ); if ( role == null ) { /* log.warn( "Could not figure out a role for the component '" + fqn + "'. " + "Please specify a role with a parameter '" + PLEXUS_ROLE_PARAMETER + "' " + "on the @" + PLEXUS_COMPONENT_TAG + " tag." ); */ return null; } } componentDescriptor.setRole( role ); // ---------------------------------------------------------------------- // Role hint // ---------------------------------------------------------------------- String roleHint = getParameter( parameters, PLEXUS_ROLE_HINT_PARAMETER ); if ( roleHint != null ) { // getLogger().debug( " Role hint: " + roleHint ); } componentDescriptor.setRoleHint( roleHint ); // ---------------------------------------------------------------------- // Version // ---------------------------------------------------------------------- String version = getParameter( parameters, PLEXUS_VERSION_PARAMETER ); componentDescriptor.setVersion( version ); // ---------------------------------------------------------------------- // Lifecycle handler // ---------------------------------------------------------------------- String lifecycleHandler = getParameter( parameters, PLEXUS_LIFECYCLE_HANDLER_PARAMETER ); componentDescriptor.setLifecycleHandler( lifecycleHandler ); // ---------------------------------------------------------------------- // Lifecycle handler // ---------------------------------------------------------------------- String instatiationStrategy = getParameter( parameters, PLEXUS_INSTANTIATION_STARTEGY_PARAMETER ); componentDescriptor.setInstantiationStrategy( instatiationStrategy ); // ---------------------------------------------------------------------- // Alias // ---------------------------------------------------------------------- componentDescriptor.setAlias( getParameter( parameters, PLEXUS_ALIAS_PARAMETER ) ); // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- findExtraParameters( PLEXUS_COMPONENT_TAG, parameters ); // ---------------------------------------------------------------------- // Requirements // ---------------------------------------------------------------------- findRequirements( classCache, componentDescriptor, javaClass ); // ---------------------------------------------------------------------- // Description // ---------------------------------------------------------------------- String comment = javaClass.getComment(); if ( comment != null ) { int i = comment.indexOf( '.' ); if ( i > 0 ) { comment = comment.substring( 0, i + 1 ); // include the dot } } componentDescriptor.setDescription( comment ); // ---------------------------------------------------------------------- // Configuration // ---------------------------------------------------------------------- XmlPlexusConfiguration configuration = new XmlPlexusConfiguration( "configuration" ); findConfiguration( configuration, javaClass ); componentDescriptor.setConfiguration( configuration ); return componentDescriptor; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private final static List IGNORED_INTERFACES = Collections.unmodifiableList( Arrays.asList( new String[]{ LogEnabled.class.getName(), Initializable.class.getName(), Configurable.class.getName(), Contextualizable.class.getName(), Disposable.class.getName(), Startable.class.getName(), } ) ); private String findRole( JavaClass javaClass ) { // ---------------------------------------------------------------------- // Remove any Plexus specific interfaces from the calculation // ---------------------------------------------------------------------- List interfaces = new ArrayList( Arrays.asList( javaClass.getImplementedInterfaces() ) ); for ( Iterator it = interfaces.iterator(); it.hasNext(); ) { JavaClass ifc = it.next(); if ( IGNORED_INTERFACES.contains( ifc.getFullyQualifiedName() ) ) { it.remove(); } } // ---------------------------------------------------------------------- // For each implemented interface, check to see if it's a candiate // interface // ---------------------------------------------------------------------- String role = null; String className = javaClass.getName(); for ( Iterator it = interfaces.iterator(); it.hasNext(); ) { JavaClass ifc = it.next(); String fqn = ifc.getFullyQualifiedName(); String pkg = ifc.getPackage(); if ( pkg == null ) { int index = fqn.lastIndexOf( '.' ); if ( index == -1 ) { // ----------------------------------------------------------------------- // This is a special case which will happen in two cases: // 1) The component is in the default/root package // 2) The interface is in another build, typically in an -api package // while the code beeing gleaned in in the -impl build. // // Since it's most likely in another package than in the default package // prepend the gleaned class' package // ----------------------------------------------------------------------- pkg = javaClass.getPackage(); fqn = pkg + "." + fqn; } else { pkg = fqn.substring( 0, index ); } } if ( fqn == null ) { fqn = ifc.getName(); } String name = fqn.substring( pkg.length() + 1 ); if ( className.endsWith( name ) ) { if ( role != null ) { /* log.warn( "Found several possible roles for component " + "'" + javaClass.getFullyQualifiedName() + "', " + "will use '" + role + "', found: " + ifc.getName() + "." ); */ } role = fqn; } } if ( role == null ) { JavaClass superClass = javaClass.getSuperJavaClass(); if ( superClass != null ) { role = findRole( superClass ); } } return role; } private void findRequirements( JavaClassCache classCache, ComponentDescriptor componentDescriptor, JavaClass javaClass ) { JavaField[] fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for requirements // ---------------------------------------------------------------------- if ( javaClass.getSuperJavaClass() != null ) { findRequirements( classCache, componentDescriptor, javaClass.getSuperJavaClass() ); } // ---------------------------------------------------------------------- // Search the current class for requirements // ---------------------------------------------------------------------- for ( int i = 0; i < fields.length; i++ ) { JavaField field = fields[i]; DocletTag tag = field.getTagByName( PLEXUS_REQUIREMENT_TAG ); if ( tag == null ) { continue; } Map parameters = new HashMap( tag.getNamedParameterMap() ); // ---------------------------------------------------------------------- // Role // ---------------------------------------------------------------------- String requirementClass = field.getType().getJavaClass().getFullyQualifiedName(); boolean isMap = requirementClass.equals( Map.class.getName() ) || requirementClass.equals( Collection.class.getName() ); try { isMap = isMap || Collection.class.isAssignableFrom( Class.forName( requirementClass ) ); } catch ( ClassNotFoundException e ) { // ignore the assignable Collection test, though this should never happen } boolean isList = requirementClass.equals( List.class.getName() ); ComponentRequirement cr; String hint = getParameter( parameters, PLEXUS_ROLE_HINT_PARAMETER ); if ( isMap || isList ) { cr = new ComponentRequirementList(); String hintList = getParameter( parameters, PLEXUS_ROLE_HINT_LIST_PARAMETER ); if ( hintList != null ) { String[] hintArr = hintList.split( "," ); ( (ComponentRequirementList) cr).setRoleHints( Arrays.asList( hintArr ) ); } } else { cr = new ComponentRequirement(); cr.setRoleHint( hint ); } String role = getParameter( parameters, PLEXUS_ROLE_PARAMETER ); if ( role == null ) { cr.setRole( requirementClass ); } else { cr.setRole( role ); } cr.setFieldName( field.getName() ); if ( isMap || isList ) { if ( hint != null ) { /* log.warn( "Field: '" + field.getName() + "': A role hint cannot be specified if the " + "field is a java.util.Map or a java.util.List" ); */ continue; } if ( role == null ) { /* log.warn( "Field: '" + field.getName() + "': A java.util.Map or java.util.List " + "requirement has to specify a '" + PLEXUS_ROLE_PARAMETER + "' parameter on " + "the @" + PLEXUS_REQUIREMENT_TAG + " tag so Plexus can know which components to " + "put in the map or list." ); */ continue; } JavaClass roleClass = classCache.getClassByName( role ); if ( role.indexOf( '.' ) == -1 && StringUtils.isEmpty( roleClass.getPackage() ) ) { role = javaClass.getPackage() + "." + roleClass.getName(); } cr.setRole( role ); findExtraParameters( PLEXUS_REQUIREMENT_TAG, parameters ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- componentDescriptor.addRequirement( cr ); } } private void findConfiguration( XmlPlexusConfiguration configuration, JavaClass javaClass ) throws ComponentGleanerException { JavaField[] fields = javaClass.getFields(); // ---------------------------------------------------------------------- // Search the super class for configurable fields. // ---------------------------------------------------------------------- if ( javaClass.getSuperJavaClass() != null ) { findConfiguration( configuration, javaClass.getSuperJavaClass() ); } // ---------------------------------------------------------------------- // Search the current class for configurable fields. // ---------------------------------------------------------------------- for ( int i = 0; i < fields.length; i++ ) { JavaField field = fields[i]; DocletTag tag = field.getTagByName( PLEXUS_CONFIGURATION_TAG ); if ( tag == null ) { continue; } Map parameters = new HashMap( tag.getNamedParameterMap() ); /* don't use the getParameter helper as we like empty strings */ String defaultValue = parameters.remove( PLEXUS_DEFAULT_VALUE_PARAMETER ); if ( defaultValue == null ) { /* log.warn( "Component: " + javaClass.getName() + ", field name: '" + field.getName() + "': " + "Currently configurable fields will not be written to the descriptor " + "without a default value." );*/ continue; } String name = deHump( field.getName() ); XmlPlexusConfiguration c; c = new XmlPlexusConfiguration( name ); c.setValue( defaultValue ); //log.debug( " Configuration: {}={}", name, defaultValue ); configuration.addChild( c ); findExtraParameters( PLEXUS_CONFIGURATION_TAG, parameters ); } } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- private void findExtraParameters( String tagName, Map parameters ) { for ( Iterator it = parameters.keySet().iterator(); it.hasNext(); ) { String s = it.next(); //log.warn( "Extra parameter on the '" + tagName + "' tag: '" + s + "'." ); } } private String getParameter( Map parameters, String parameter ) { String value = parameters.remove( parameter ); if ( StringUtils.isEmpty( value ) ) { return null; } return value; } }././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/ClassComponentGleaner.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/ClassComp0000644000175000017500000000213611124722742033374 0ustar twernertwernerpackage org.codehaus.plexus.metadata.gleaner; /* * Copyright (C) 2007 the original author or authors. * * Licensed 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 org.codehaus.plexus.component.repository.ComponentDescriptor; /** * Interface for component gleaners which glean off of compiled classes.. * * @version $Id: ClassComponentGleaner.java 7966 2008-12-25 15:25:22Z bentmann $ */ public interface ClassComponentGleaner { String ROLE = ClassComponentGleaner.class.getName(); ComponentDescriptor glean(String className, ClassLoader cl) throws ComponentGleanerException; }././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/AnnotationComponentGleaner.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/Annotatio0000644000175000017500000002102211124722742033437 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Modifier; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Enumeration; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Configuration; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; import org.codehaus.plexus.metadata.ann.AnnClass; import org.codehaus.plexus.metadata.ann.AnnField; import org.codehaus.plexus.metadata.ann.AnnReader; import org.codehaus.plexus.util.IOUtil; /** * A class component gleaner which inspects each type for org.codehaus.plexus.component.annotations.* annotations * and when found translates them into a {@link ComponentDescriptor}. * * @version $Id: AnnotationComponentGleaner.java 7966 2008-12-25 15:25:22Z bentmann $ */ public class AnnotationComponentGleaner extends ComponentGleanerSupport implements ClassComponentGleaner { public ComponentDescriptor glean(String className, ClassLoader cl) throws ComponentGleanerException { assert className != null; assert cl != null; AnnClass annClass = readClass(className.replace('.', '/'), cl); // Skip abstract classes if (Modifier.isAbstract(annClass.getAccess())) { return null; } Component anno = annClass.getAnnotation(Component.class); if (anno == null) { return null; } ComponentDescriptor component = new ComponentDescriptor(); component.setRole(anno.role().getName()); component.setRoleHint(filterEmptyAsNull(anno.hint())); component.setImplementation(className); component.setVersion(filterEmptyAsNull(anno.version())); component.setComponentType(filterEmptyAsNull(anno.type())); component.setInstantiationStrategy(filterEmptyAsNull(anno.instantiationStrategy())); component.setLifecycleHandler(filterEmptyAsNull(anno.lifecycleHandler())); component.setComponentProfile(filterEmptyAsNull(anno.profile())); component.setComponentComposer(filterEmptyAsNull(anno.composer())); component.setComponentConfigurator(filterEmptyAsNull(anno.configurator())); component.setComponentFactory(filterEmptyAsNull(anno.factory())); component.setDescription(filterEmptyAsNull(anno.description())); component.setAlias(filterEmptyAsNull(anno.alias())); component.setIsolatedRealm(anno.isolatedRealm()); for (AnnClass c : getClasses(annClass, cl)) { for (AnnField field : c.getFields().values()) { ComponentRequirement requirement = findRequirement(field, c, cl); if (requirement != null) { component.addRequirement(requirement); } PlexusConfiguration config = findConfiguration(field, c, cl); if (config != null) { addChildConfiguration(component, config); } } // // TODO: Inspect methods? // } return component; } private AnnClass readClass(String className, ClassLoader cl) throws ComponentGleanerException { InputStream is = null; try { // only read annotation from project classes (not jars) Enumeration en = cl.getResources( className + ".class" ); while ( en.hasMoreElements() ) { URL url = en.nextElement(); if( url.toString().startsWith( "file:" ) ) { is = url.openStream(); return AnnReader.read( is, cl ); } } throw new ComponentGleanerException("Can't find class " + className); } catch (IOException ex) { throw new ComponentGleanerException("Can't read class " + className, ex); } finally { IOUtil.close(is); } } private AnnClass readClass2(String className, ClassLoader cl) throws ComponentGleanerException { InputStream is = null; try { is = cl.getResourceAsStream(className + ".class"); return AnnReader.read(is, cl); } catch (IOException ex) { throw new ComponentGleanerException("Can't read class " + className, ex); } finally { IOUtil.close(is); } } /** * Returns a list of all of the classes which the given type inherits from. */ private List getClasses(AnnClass annClass, ClassLoader cl) throws ComponentGleanerException { assert annClass != null; List classes = new ArrayList(); while(annClass!=null) { classes.add(annClass); if(annClass.getSuperName()!=null) { annClass = readClass2(annClass.getSuperName(), cl); } else { break; } // // TODO: See if we need to include interfaces here too? // } return classes; } private ComponentRequirement findRequirement(final AnnField field, AnnClass annClass, ClassLoader cl) throws ComponentGleanerException { assert field != null; Requirement anno = field.getAnnotation(Requirement.class); if (anno == null) { return null; } String fieldType = field.getType(); // TODO implement type resolution without loading classes Class type; try { type = Class.forName(fieldType, false, cl); } catch (ClassNotFoundException ex) { // TODO Auto-generated catch block throw new ComponentGleanerException("Can't load class " + fieldType); } ComponentRequirement requirement; if (isRequirementListType(type)) { requirement = new ComponentRequirementList(); String[] hints = anno.hints(); if (hints != null && hints.length > 0) { ((ComponentRequirementList)requirement).setRoleHints(Arrays.asList(hints)); } // // TODO: See if we can glean any type details out of any generic information from the map or collection // } else { requirement = new ComponentRequirement(); requirement.setRoleHint(filterEmptyAsNull(anno.hint())); } // TODO need to read default annotation values // if (anno.role()==null || anno.role().isAssignableFrom(Object.class)) { if (anno.role().isAssignableFrom(Object.class)) { requirement.setRole(type.getName()); } else { requirement.setRole(anno.role().getName()); } requirement.setFieldName(field.getName()); requirement.setFieldMappingType(type.getName()); return requirement; } private PlexusConfiguration findConfiguration(AnnField field, AnnClass c, ClassLoader cl) { assert field != null; Configuration anno = field.getAnnotation(Configuration.class); if (anno == null) { return null; } String name = filterEmptyAsNull(anno.name()); if (name == null) { name = field.getName(); } name = deHump(name); XmlPlexusConfiguration config = new XmlPlexusConfiguration(name); String value = filterEmptyAsNull(anno.value()); if (value != null) { config.setValue(value); } return config; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/ComponentGleanerSupport.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/Component0000644000175000017500000000457611124722742033464 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.gleaner; import java.util.Collection; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; /** * Support for component gleaner implementations. * * @version $Id: ComponentGleanerSupport.java 7966 2008-12-25 15:25:22Z bentmann $ */ public abstract class ComponentGleanerSupport { private static final String EMPTY_STRING = ""; protected String filterEmptyAsNull(final String value) { if (value == null) { return null; } else if (EMPTY_STRING.equals(value.trim())) { return null; } else { return value; } } protected boolean isRequirementListType(final Class type) { // assert type != null; return Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type); } protected void addChildConfiguration(final ComponentDescriptor component, final PlexusConfiguration config) { // assert component != null; // assert config != null; if (!component.hasConfiguration()) { component.setConfiguration(new XmlPlexusConfiguration("configuration")); } component.getConfiguration().addChild(config); } protected String deHump(final String string) { // assert string != null; StringBuffer buff = new StringBuffer(); for (int i = 0; i < string.length(); i++) { if (i != 0 && Character.isUpperCase(string.charAt(i))) { buff.append('-'); } buff.append(string.charAt(i)); } return buff.toString().trim().toLowerCase(); } }././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/ComponentGleanerException.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/Component0000644000175000017500000000327011054033060033440 0ustar twernertwernerpackage org.codehaus.plexus.metadata.gleaner; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ComponentGleanerException.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentGleanerException extends Exception { public ComponentGleanerException( String message ) { super( message ); } public ComponentGleanerException( String message, Throwable cause ) { super( message, cause ); } public ComponentGleanerException( Throwable cause ) { super( cause ); } }././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceComponentGleaner.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/gleaner/SourceCom0000644000175000017500000000230611124722742033406 0ustar twernertwernerpackage org.codehaus.plexus.metadata.gleaner; /* * Copyright (C) 2007 the original author or authors. * * Licensed 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 org.codehaus.plexus.component.repository.ComponentDescriptor; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaClassCache; /** * Interface for component gleaners which glean off of source code. * * @version $Id: SourceComponentGleaner.java 7966 2008-12-25 15:25:22Z bentmann $ */ public interface SourceComponentGleaner { String ROLE = SourceComponentGleaner.class.getName(); ComponentDescriptor glean(JavaClassCache classCache, JavaClass javaClass) throws ComponentGleanerException; }././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/DefaultComponentDescriptorWriter.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/DefaultComponentD0000644000175000017500000002167111107373274033456 0ustar twernertwerner/* * The MIT License * * Copyright (c) 2007, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ package org.codehaus.plexus.metadata; import java.io.IOException; import java.io.Writer; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentRequirement; import org.codehaus.plexus.component.repository.ComponentRequirementList; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.configuration.PlexusConfiguration; import org.codehaus.plexus.configuration.PlexusConfigurationException; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.XMLWriter; /** * Serializes a {@link ComponentSetDescriptor}. * * @author Kenney Westerhof * @author Jason van Zyl * @author Trygve Laugstøl */ public class DefaultComponentDescriptorWriter implements ComponentDescriptorWriter { private static final String LS = System.getProperty( "line.separator" ); public void writeDescriptorSet( Writer writer, ComponentSetDescriptor componentSetDescriptor, boolean containerDescriptor ) throws ComponentDescriptorWriteException, IOException { try { XMLWriter w = new PrettyPrintXMLWriter( writer ); w.startElement( containerDescriptor ? "plexus" : "component-set" ); writeComponents( w, componentSetDescriptor.getComponents() ); writeDependencies( w, componentSetDescriptor.getDependencies() ); w.endElement(); writer.write( LS ); // Flush, but don't close the writer... we are not its owner writer.flush(); } catch ( PlexusConfigurationException e ) { throw new ComponentDescriptorWriteException( "Internal error while writing out the configuration", e ); } } private void writeComponents( XMLWriter w, List> componentDescriptors ) throws ComponentDescriptorWriteException, PlexusConfigurationException { if ( componentDescriptors == null ) { return; } w.startElement( "components" ); for ( ComponentDescriptor cd : componentDescriptors ) { w.startElement( "component" ); element( w, "role", cd.getRole() ); element( w, "role-hint", cd.getRoleHint() ); element( w, "implementation", cd.getImplementation() ); element( w, "version", cd.getVersion() ); element( w, "component-type", cd.getComponentType() ); element( w, "instantiation-strategy", cd.getInstantiationStrategy() ); element( w, "lifecycle-handler", cd.getLifecycleHandler() ); element( w, "component-profile", cd.getComponentProfile() ); element( w, "component-composer", cd.getComponentComposer() ); element( w, "component-configurator", cd.getComponentConfigurator() ); element( w, "component-factory", cd.getComponentFactory() ); element( w, "description", cd.getDescription() ); element( w, "alias", cd.getAlias() ); element( w, "isolated-realm", Boolean.toString( cd.isIsolatedRealm() ) ); writeRequirements( w, cd.getRequirements() ); writeConfiguration( w, cd.getConfiguration() ); w.endElement(); } w.endElement(); } public void writeDependencies( XMLWriter w, List deps ) { if ( deps == null || deps.size() == 0 ) { return; } w.startElement( "dependencies" ); for ( ComponentDependency dep : deps ) { writeDependencyElement( dep, w ); } w.endElement(); } private void writeDependencyElement( ComponentDependency dependency, XMLWriter w ) { w.startElement( "dependency" ); String groupId = dependency.getGroupId(); element( w, "groupId", groupId ); String artifactId = dependency.getArtifactId(); element( w, "artifactId", artifactId ); String type = dependency.getType(); if ( type != null ) { element( w, "type", type ); } String version = dependency.getVersion(); element( w, "version", version ); w.endElement(); } private void writeRequirements( XMLWriter w, List requirements ) { if ( requirements == null || requirements.size() == 0 ) { return; } w.startElement( "requirements" ); for ( ComponentRequirement cr : requirements ) { w.startElement( "requirement" ); element( w, "role", cr.getRole() ); if ( cr instanceof ComponentRequirementList ) { List hints = ( (ComponentRequirementList) cr ).getRoleHints(); if ( hints != null ) { w.startElement( "role-hints" ); for ( String roleHint : hints ) { w.startElement( "role-hint" ); w.writeText( roleHint ); w.endElement(); } w.endElement(); } } else { element( w, "role-hint", cr.getRoleHint() ); } element( w, "field-name", cr.getFieldName() ); w.endElement(); } w.endElement(); } private void writeConfiguration( XMLWriter w, PlexusConfiguration configuration ) throws ComponentDescriptorWriteException, PlexusConfigurationException { if ( configuration == null || configuration.getChildCount() == 0 ) { return; } if ( !configuration.getName().equals( "configuration" ) ) { throw new ComponentDescriptorWriteException( "The root node of the configuration must be 'configuration'."); } writePlexusConfiguration( w, configuration ); } private void writePlexusConfiguration( XMLWriter xmlWriter, PlexusConfiguration c ) throws PlexusConfigurationException { if ( c.getAttributeNames().length == 0 && c.getChildCount() == 0 && c.getValue() == null ) { return; } xmlWriter.startElement( c.getName() ); // ---------------------------------------------------------------------- // Write the attributes // ---------------------------------------------------------------------- String[] attributeNames = c.getAttributeNames(); for ( String attributeName : attributeNames ) { xmlWriter.addAttribute( attributeName, c.getAttribute( attributeName ) ); } // ---------------------------------------------------------------------- // Write the children // ---------------------------------------------------------------------- PlexusConfiguration[] children = c.getChildren(); if ( children.length > 0 ) { for ( PlexusConfiguration aChildren : children ) { writePlexusConfiguration( xmlWriter, aChildren ); } } else { String value = c.getValue(); if ( value != null ) { xmlWriter.writeText( value ); } } xmlWriter.endElement(); } private void element( XMLWriter w, String name, String value ) { if ( value == null ) { return; } w.startElement( name ); w.writeText( value ); w.endElement(); } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/MetadataGenerator.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/MetadataGenerator0000644000175000017500000000026011114626430033452 0ustar twernertwernerpackage org.codehaus.plexus.metadata; public interface MetadataGenerator { void generateDescriptor( MetadataGenerationRequest configuration ) throws Exception; } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/PlexusMetadataGeneratorCli.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/PlexusMetadataGen0000644000175000017500000000536011125010723033436 0ustar twernertwernerpackage org.codehaus.plexus.metadata; import java.io.File; import java.util.Arrays; import java.util.Collections; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.OptionBuilder; import org.apache.commons.cli.Options; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.tools.cli.AbstractCli; public class PlexusMetadataGeneratorCli extends AbstractCli { public static final char SOURCE_DIRECTORY = 's'; public static final char SOURCE_ENCODING = 'e'; public static final char CLASSES_DIRECTORY = 'c'; public static final char OUTPUT_FILE = 'o'; public static final char DESCRIPTORS_DIRECTORY = 'm'; public static void main( String[] args ) throws Exception { new PlexusMetadataGeneratorCli().execute( args ); } @Override public String getPomPropertiesPath() { return "META-INF/maven/org.codehaus.plexus/plexus-metadata-generator/pom.properties"; } @Override @SuppressWarnings("static-access") public Options buildCliOptions( Options options ) { options.addOption( OptionBuilder.withLongOpt( "source" ).hasArg().withDescription( "Source directory." ).create( SOURCE_DIRECTORY ) ); options.addOption( OptionBuilder.withLongOpt( "encoding" ).hasArg().withDescription( "Source file encoding." ).create( SOURCE_ENCODING ) ); options.addOption( OptionBuilder.withLongOpt( "classes" ).hasArg().withDescription( "Classes directory." ).create( CLASSES_DIRECTORY ) ); options.addOption( OptionBuilder.withLongOpt( "output" ).hasArg().withDescription( "Output directory." ).create( OUTPUT_FILE ) ); options.addOption( OptionBuilder.withLongOpt( "descriptors" ).hasArg().withDescription( "Descriptors directory." ).create( DESCRIPTORS_DIRECTORY ) ); return options; } public void invokePlexusComponent( CommandLine cli, PlexusContainer plexus ) throws Exception { MetadataGenerator metadataGenerator = plexus.lookup( MetadataGenerator.class ); MetadataGenerationRequest request = new MetadataGenerationRequest(); request.classesDirectory = new File( cli.getOptionValue( CLASSES_DIRECTORY ) ); request.classpath = Collections.emptyList(); request.sourceDirectories = Arrays.asList( new String[]{ new File( cli.getOptionValue( SOURCE_DIRECTORY ) ).getAbsolutePath() } ); request.sourceEncoding = cli.getOptionValue( SOURCE_ENCODING ); request.useContextClassLoader = true; request.outputFile = new File( cli.getOptionValue( OUTPUT_FILE ) ); request.componentDescriptorDirectory = new File( cli.getOptionValue( DESCRIPTORS_DIRECTORY ) ); metadataGenerator.generateDescriptor( request ); } } ././@LongLink0000000000000000000000000000017400000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescriptorExtractorSupport.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescript0000644000175000017500000000445611202040413033523 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata; import java.util.HashMap; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * Support for {@link ComponentDescriptorExtractor} implementations. * * @version $Id: ComponentDescriptorExtractorSupport.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ public abstract class ComponentDescriptorExtractorSupport implements ComponentDescriptorExtractor { protected Map> getDefaultsByRole( final ComponentDescriptor[] roleDefaults ) { Map> defaultsByRole = new HashMap>(); if ( roleDefaults != null ) { for ( int i = 0; i < roleDefaults.length; i++ ) { String role = roleDefaults[i].getRole(); if ( role == null ) { throw new IllegalArgumentException( "Invalid role defaults; found null role in: " + roleDefaults[i] ); } defaultsByRole.put( role, roleDefaults[i] ); } } return defaultsByRole; } protected void applyDefaults( ComponentDescriptor descriptor, Map> defaultsByRole ) { assert descriptor != null; assert defaultsByRole != null; if ( defaultsByRole.containsKey( descriptor.getRole() ) ) { ComponentDescriptor defaults = defaultsByRole.get( descriptor.getRole() ); if ( descriptor.getInstantiationStrategy() == null ) { descriptor.setInstantiationStrategy( defaults.getInstantiationStrategy() ); } } } }plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/0000755000175000017500000000000011226720062031241 5ustar twernertwerner././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MergeStrategy.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MergeStrate0000644000175000017500000000335711054033060033410 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.support.Mergeable; /** * @author Rahul Thakur * @version $Id: MergeStrategy.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public interface MergeStrategy { /** * Merges a dominant {@link Mergeable} instance with a recessive one. * * @param dElt Dominant {@link Mergeable} instance. * @param rElt Recessive {@link Mergeable} instance. * @throws MergeException TODO */ void apply( Mergeable dElt, Mergeable rElt ) throws MergeException; } ././@LongLink0000000000000000000000000000016200000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/ComponentsXmlMerger.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/ComponentsX0000644000175000017500000000443011202040413033427 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.metadata.merge.support.ComponentSetElement; import org.jdom.Document; /** * @author Rahul Thakur * @version $Id: ComponentsXmlMerger.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ @Component(role=Merger.class,hint="componentsXml") public class ComponentsXmlMerger extends AbstractMerger { /** * @see Merger#merge(Document, Document) */ public Document merge( Document dDocument, Document rDocument ) throws MergeException { // TODO: Ideally we don't want to manipulate the original // dominant document but use its copy for merge. //Document mDoc = (Document) dDocument.clone(); // doesn't merge properly Document mDoc = dDocument; ComponentSetElement dCSE = new ComponentSetElement( mDoc.getRootElement() ); ComponentSetElement rCSE = new ComponentSetElement( rDocument.getRootElement() ); dCSE.merge( rCSE ); // the contents are merged into the dominant document DOM. return mDoc; } } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/0000755000175000017500000000000011226720062032755 5ustar twernertwerner././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/ComponentsElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Com0000644000175000017500000000536511054033060033421 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.List; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentsElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentsElement extends AbstractMergeableElementList { static final DescriptorTag TAG = new DescriptorTag( "components", true, ComponentsElement.class ); private List conflictVerificationkeys = new ArrayList(); public ComponentsElement( Element element ) { super( element ); conflictVerificationkeys.add( ComponentElement.ROLE.getTagName() ); conflictVerificationkeys.add( ComponentElement.ROLE_HINT.getTagName() ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{ComponentElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return ( me instanceof ComponentsElement ); } protected List getElementNamesForConflictChecks( List defaultList ) { // Allow to return custom keys for conflict checks/resolution. return this.conflictVerificationkeys; } protected String getTagNameForRecurringMergeable() { return ComponentElement.TAG.getTagName(); } protected List getElementNamesForConflictResolution( List defaultList ) { // TODO: how is this different from getElementNamesForConflictChecks? List l = new ArrayList(); l.add( ComponentElement.ROLE.getTagName() ); l.add( ComponentElement.ROLE_HINT.getTagName() ); return l; } } ././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Mergeable.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Mer0000644000175000017500000000543211054033060033421 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Element; /** * Interface that marks an implementing entity as mergeable.

* Not all the elements/tags are expected to implement this interface.
* It should be implemented by elements/tags that need to have a certain control on how elements of the same type are merged with them. * * @author Rahul Thakur * @version $Id: Mergeable.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public interface Mergeable { /** * Merges an element of same type. * * @param me Another entity that is mergeable. * @throws MergeException if there was an error merging the mergeables. */ void merge( Mergeable me ) throws MergeException; /** * Applies the passed in {@link MergeStrategy} to merge two {@link Mergeable} instance.

* * @param me Recessive {@link Mergeable} instance. * @param strategy {@link MergeStrategy} to apply for merging. * @throws MergeException if there was an error while merging. */ void merge( Mergeable me, MergeStrategy strategy ) throws MergeException; /** * Returns the wrapped up JDom {@link Element} instance that was used to create this Mergeable. * * @return the wrapped up JDom {@link Element} instance. */ Element getElement(); /** * Returns an array of tags/elements that are allowed under the current * element. * * @return the allowedTags */ DescriptorTag[] getAllowedTags(); } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/ComponentSetElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Com0000644000175000017500000000336411054033060033416 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentSetElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentSetElement extends AbstractMergeableElement { public ComponentSetElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{ComponentsElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ComponentSetElement; } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/PlexusRootElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Ple0000644000175000017500000000342311054033060033414 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: PlexusRootElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class PlexusRootElement extends AbstractMergeableElement { public PlexusRootElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { // TODO: add the managers, etc return new DescriptorTag[]{ComponentsElement.TAG}; } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof PlexusRootElement; } } ././@LongLink0000000000000000000000000000016600000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/MergeStrategies.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Mer0000644000175000017500000000622111054033060033416 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Collections; import java.util.List; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; /** * Collection of available Merge Strategies.

* TODO: Revisit and factor {@link Mergeable#merge(Mergeable)} to use a {@link MergeStrategy}. * * @author Rahul Thakur * @version $Id: MergeStrategies.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class MergeStrategies { /** * {@link MergeStrategy} implementation wherein the elements are merged * down to the deepest available {@link Mergeable} instance in the DOM tree. */ public static final MergeStrategy DEEP = new MergeStrategy() { public void apply( Mergeable dElt, Mergeable rElt ) throws MergeException { dElt.merge( rElt ); } }; /** * {@link MergeStrategy} implementation wherein only the element on * which the merge operation is called is 'merged'. The merge does not * traverse the DOM tree any further. */ public static final MergeStrategy SHALLOW = new MergeStrategy() { /** * @throws MergeException * @see org.codehaus.plexus.metadata.merge.MergeStrategy#apply(Mergeable,Mergeable) */ public void apply( Mergeable dElt, Mergeable rElt ) throws MergeException { AbstractMergeableElement dame = (AbstractMergeableElement) dElt; AbstractMergeableElement rame = (AbstractMergeableElement) rElt; // check if the dominant was in conflict with recessive. List elementNames = dame.getElementNamesForConflictResolution( Collections.EMPTY_LIST ); if ( !dame.isRecessiveElementInConflict( rame, elementNames ) ) { // no conflict, simply add recessive to dominant's parent dame.getElement().addContent( rame.getElement() ); } } }; } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/PlexusXmlTag.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Ple0000644000175000017500000000473011054033060033416 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /** * All allowable tags in components.xml and their bindings to * {@link org.codehaus.plexus.metadata.merge.support.Mergeable} counterparts (if required). *

* This implementation may change.
* TODO Might be an idea factor and set up the list of allowed tags here itself. * * @author Rahul Thakur * @version $Id: PlexusXmlTag.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class PlexusXmlTag extends DescriptorTag { public static final PlexusXmlTag COMPONENT_SET = new PlexusXmlTag( "component-set", false, ComponentSetElement.class ); public static final PlexusXmlTag COMPONENTS = new PlexusXmlTag( "components", true, ComponentsElement.class ); public static final PlexusXmlTag COMPONENT = new PlexusXmlTag( "component", true, ComponentElement.class ); public static final PlexusXmlTag ROLE = new PlexusXmlTag( "role" ); public static final PlexusXmlTag ROLE_HINT = new PlexusXmlTag( "role-hint" ); public static final PlexusXmlTag FIELD_NAME = new PlexusXmlTag( "field-name" ); public static final PlexusXmlTag IMPLEMENTATION = new PlexusXmlTag( "implementation" ); public static final PlexusXmlTag LIFECYCLE_HANDLER = new PlexusXmlTag( "lifecycle-handler", false, null ); public static final PlexusXmlTag REQUIREMENTS = new PlexusXmlTag( "requirements", true, RequirementsElement.class ); public static final PlexusXmlTag CONFIGURATION = new PlexusXmlTag( "configuration", true, ConfigurationElement.class ); public static final PlexusXmlTag REQUIREMENT = new PlexusXmlTag( "requirement", true, RequirementElement.class ); /** * @param tagName * @param isMultipleAllowed * @param mergeableClass Class that wraps this tag (as JDom element) and provides for merging same tags. */ private PlexusXmlTag( String tagName, boolean isMultipleAllowed, Class mergeableClass ) { super( tagName, isMultipleAllowed, mergeableClass ); } /** * By default we don't allow multiples of same tag names. * * @param tagName */ private PlexusXmlTag( String tagName ) { super( tagName, false, null ); } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/AbstractMergeableElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Abs0000644000175000017500000001626011054033060033404 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Content; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: AbstractMergeableElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableElement extends AbstractMergeableSupport { public AbstractMergeableElement( Element element ) { super( element ); } /** * Detects if there was a conflict, that is the specified element was * present in both dominant and recessive element-sets. *

* This delegates to * {@link #isRecessiveElementInConflict(AbstractMergeableElement,List)}. * * @param re Recessive element. * @param eltName Element name to test for. * @return true if there was a conflict of element. * @deprecated use {@link #isRecessiveElementInConflict(AbstractMergeableElement,List)} instead. */ protected boolean isRecessiveElementInConflict( AbstractMergeableElement re, String eltName ) { // return (null != getChild (eltName) && null != re.getChild (eltName)); List l = new ArrayList(); l.add( eltName ); return isRecessiveElementInConflict( re, l ); } /** * Detects if there was a conflict, that is the specified element was * present in both dominant and recessive element-sets. *

* Use this to determine conflicts when the Dominant and Recessive element * sets are keyed with Composite keys.
* For instance: <component> is keyed on * <role> and <role-hint>. * * @param re * @param eltNameList List of elements that will be checked for values in both dominant and recessive sets. * @return */ protected boolean isRecessiveElementInConflict( AbstractMergeableElement re, List eltNameList ) { // give opportunity to subclasses to provide any custom Composite keys // for conflict checks. eltNameList = getElementNamesForConflictResolution( eltNameList ); if ( null == eltNameList || eltNameList.size() == 0 ) { return false; } // assuming the elements will conflict. for ( Iterator it = eltNameList.iterator(); it.hasNext(); ) { String eltName = (String) it.next(); String dEltValue = getChildTextTrim( eltName ); String rEltValue = re.getChildTextTrim( eltName ); if ( null == dEltValue || null == rEltValue || !dEltValue.equals( rEltValue ) ) { return false; } } return true; } /** * Determines if the Element to be merged is to be sourced from Recessive * Element set. * * @param re Recessive element. * @param eltName Element name to test for. * @return */ protected boolean mergeableElementComesFromRecessive( AbstractMergeableElement re, String eltName ) { return null == getChildText( eltName ) && null != re.getChildText( eltName ); } /** * Simply delegate to * * @see Mergeable#merge(Mergeable,org.codehaus.plexus.metadata.merge.MergeStrategy) */ public void merge( Mergeable me, MergeStrategy strategy ) throws MergeException { // TODO set up a unit test for this! strategy.apply( this, me ); } public void merge( Mergeable me ) throws MergeException { if ( !isExpectedElementType( me ) ) { // if (getLogger().isErrorEnabled) // getLogger().error ("Cannot Merge dissimilar elements. (Expected : '" + getClass ().getName () + "', found '" + me.getClass ().getName () + "')"); throw new MergeException( "Cannot Merge dissimilar elements. " + "(Expected : '" + getClass().getName() + "', found '" + me.getClass().getName() + "')" ); } // recessive Component Element. AbstractMergeableElement rce = (AbstractMergeableElement) me; Set allowedTags = new HashSet(); for ( int i = 0; i < getAllowedTags().length; i++ ) { String tagName = getAllowedTags()[i].getTagName(); allowedTags.add( tagName ); List defaultConflictChecklist = new ArrayList(); defaultConflictChecklist.add( tagName ); if ( !isRecessiveElementInConflict( rce, defaultConflictChecklist ) && mergeableElementComesFromRecessive( rce, tagName ) ) { this.addContent( (Element) rce.getChild( tagName ).clone() ); // else dominant wins in anycase! } else if ( getAllowedTags()[i].isMergeable() && isRecessiveElementInConflict( rce, defaultConflictChecklist ) ) { // this allows for merging multiple/list of elements. try { getAllowedTags()[i].createMergeable( this.getChild( tagName ) ) .merge( getAllowedTags()[i].createMergeable( rce.getChild( tagName ) ), getDefaultMergeStrategy() ); } catch ( Exception e ) { // TODO log to error throw new MergeException( "Unable to create Mergeable instance for tag " + "'" + getAllowedTags()[i] + "'.", e ); } } } for ( Iterator i = me.getElement().getChildren().iterator(); i.hasNext(); ) { Element child = (Element) i.next(); if ( !allowedTags.contains( child.getName() ) ) { // not yet merged, copy over element.addContent( (Content) child.clone() ); } } } } ././@LongLink0000000000000000000000000000017700000000000011572 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/AbstractMergeableSupport.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Abs0000644000175000017500000003744511054033060033414 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.Collection; import java.util.Iterator; import java.util.List; import org.codehaus.plexus.metadata.merge.MergeException; import org.codehaus.plexus.metadata.merge.MergeStrategy; import org.jdom.Attribute; import org.jdom.Content; import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; import org.jdom.Parent; import org.jdom.filter.Filter; /** * @author Rahul Thakur * @version $Id: AbstractMergeableSupport.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableSupport implements Mergeable { /** * Wrapped JDOM element. */ protected Element element; /** * The default merging strategy used. */ private static final MergeStrategy DEFAULT_MERGE_STRATEGY = MergeStrategies.DEEP; public AbstractMergeableSupport( Element element ) { this.element = element; } public abstract void merge( Mergeable me ) throws MergeException; /** * Determines if the passed in {@link Mergeable} was of same type as this * class. * * @param me {@link Mergeable} instance to test. * @return true if the passed in Mergeable can be merged with * the current Mergeable. */ protected abstract boolean isExpectedElementType( Mergeable me ); // ---------------------------------------------------------------------- // Methods delegated on wrapped JDOM element. // ---------------------------------------------------------------------- public Element addContent( Collection collection ) { return element.addContent( collection ); } public Element addContent( Content child ) { return element.addContent( child ); } public Element addContent( int index, Collection c ) { return element.addContent( index, c ); } public Element addContent( int index, Content child ) { return element.addContent( index, child ); } public Element addContent( String str ) { return element.addContent( str ); } public void addNamespaceDeclaration( Namespace additional ) { element.addNamespaceDeclaration( additional ); } public Object clone() { return element.clone(); } public List cloneContent() { return element.cloneContent(); } public Content detach() { return element.detach(); } public boolean equals( Object obj ) { return element.equals( obj ); } public List getAdditionalNamespaces() { return element.getAdditionalNamespaces(); } public Attribute getAttribute( String name, Namespace ns ) { return element.getAttribute( name, ns ); } public Attribute getAttribute( String name ) { return element.getAttribute( name ); } public List getAttributes() { return element.getAttributes(); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,org.jdom.Namespace,java.lang.String) */ public String getAttributeValue( String name, Namespace ns, String def ) { return element.getAttributeValue( name, ns, def ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,org.jdom.Namespace) */ public String getAttributeValue( String name, Namespace ns ) { return element.getAttributeValue( name, ns ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String,java.lang.String) */ public String getAttributeValue( String name, String def ) { return element.getAttributeValue( name, def ); } /** * @see org.jdom.Element#getAttributeValue(java.lang.String) */ public String getAttributeValue( String name ) { return element.getAttributeValue( name ); } /** * @return * @see org.jdom.Element#getChild(java.lang.String,org.jdom.Namespace) */ public Element getChild( String name, Namespace ns ) { return element.getChild( name, ns ); } /** * @see org.jdom.Element#getChild(java.lang.String) */ public Element getChild( String name ) { return element.getChild( name ); } /** * @see org.jdom.Element#getChildren() */ public List getChildren() { return element.getChildren(); } /** * @see org.jdom.Element#getChildren(java.lang.String,org.jdom.Namespace) */ public List getChildren( String name, Namespace ns ) { return element.getChildren( name, ns ); } /** * @see org.jdom.Element#getChildren(java.lang.String) */ public List getChildren( String name ) { return element.getChildren( name ); } /** * @see org.jdom.Element#getChildText(java.lang.String,org.jdom.Namespace) */ public String getChildText( String name, Namespace ns ) { return element.getChildText( name, ns ); } /** * @see org.jdom.Element#getChildText(java.lang.String) */ public String getChildText( String name ) { return element.getChildText( name ); } /** * @see org.jdom.Element#getChildTextNormalize(java.lang.String,org.jdom.Namespace) */ public String getChildTextNormalize( String name, Namespace ns ) { return element.getChildTextNormalize( name, ns ); } /** * @see org.jdom.Element#getChildTextNormalize(java.lang.String) */ public String getChildTextNormalize( String name ) { return element.getChildTextNormalize( name ); } /** * @see org.jdom.Element#getChildTextTrim(java.lang.String,org.jdom.Namespace) */ public String getChildTextTrim( String name, Namespace ns ) { return element.getChildTextTrim( name, ns ); } /** * @see org.jdom.Element#getChildTextTrim(java.lang.String) */ public String getChildTextTrim( String name ) { return element.getChildTextTrim( name ); } /** * @see org.jdom.Element#getContent() */ public List getContent() { return element.getContent(); } /** * @see org.jdom.Element#getContent(org.jdom.filter.Filter) */ public List getContent( Filter filter ) { return element.getContent( filter ); } /** * @see org.jdom.Element#getContent(int) */ public Content getContent( int index ) { return element.getContent( index ); } /** * @return * @see org.jdom.Element#getContentSize() */ public int getContentSize() { return element.getContentSize(); } /** * @see org.jdom.Element#getDescendants() */ public Iterator getDescendants() { return element.getDescendants(); } /** * @see org.jdom.Element#getDescendants(org.jdom.filter.Filter) */ public Iterator getDescendants( Filter filter ) { return element.getDescendants( filter ); } /** * @see org.jdom.Content#getDocument() */ public Document getDocument() { return element.getDocument(); } /** * @see org.jdom.Element#getName() */ public String getName() { return element.getName(); } /** * @see org.jdom.Element#getNamespace() */ public Namespace getNamespace() { return element.getNamespace(); } /** * @see org.jdom.Element#getNamespace(java.lang.String) */ public Namespace getNamespace( String prefix ) { return element.getNamespace( prefix ); } /** * @see org.jdom.Element#getNamespacePrefix() */ public String getNamespacePrefix() { return element.getNamespacePrefix(); } /** * @see org.jdom.Element#getNamespaceURI() */ public String getNamespaceURI() { return element.getNamespaceURI(); } /** * @see org.jdom.Content#getParent() */ public Parent getParent() { return element.getParent(); } /** * @see org.jdom.Content#getParentElement() */ public Element getParentElement() { return element.getParentElement(); } /** * @see org.jdom.Element#getQualifiedName() */ public String getQualifiedName() { return element.getQualifiedName(); } /** * @see org.jdom.Element#getText() */ public String getText() { return element.getText(); } /** * @see org.jdom.Element#getTextNormalize() */ public String getTextNormalize() { return element.getTextNormalize(); } /** * @see org.jdom.Element#getTextTrim() */ public String getTextTrim() { return element.getTextTrim(); } /** * @see org.jdom.Element#getValue() */ public String getValue() { return element.getValue(); } /** * @see java.lang.Object#hashCode() */ public int hashCode() { return element.hashCode(); } /** * @see org.jdom.Element#indexOf(org.jdom.Content) */ public int indexOf( Content child ) { return element.indexOf( child ); } /** * @see org.jdom.Element#isAncestor(org.jdom.Element) */ public boolean isAncestor( Element element ) { return element.isAncestor( element ); } /** * @see org.jdom.Element#isRootElement() */ public boolean isRootElement() { return element.isRootElement(); } /** * @see org.jdom.Element#removeAttribute(org.jdom.Attribute) */ public boolean removeAttribute( Attribute attribute ) { return element.removeAttribute( attribute ); } /** * @see org.jdom.Element#removeAttribute(java.lang.String,org.jdom.Namespace) */ public boolean removeAttribute( String name, Namespace ns ) { return element.removeAttribute( name, ns ); } /** * @see org.jdom.Element#removeAttribute(java.lang.String) */ public boolean removeAttribute( String name ) { return element.removeAttribute( name ); } /** * @see org.jdom.Element#removeChild(java.lang.String,org.jdom.Namespace) */ public boolean removeChild( String name, Namespace ns ) { return element.removeChild( name, ns ); } /** * @see org.jdom.Element#removeChild(java.lang.String) */ public boolean removeChild( String name ) { return element.removeChild( name ); } /** * @see org.jdom.Element#removeChildren(java.lang.String,org.jdom.Namespace) */ public boolean removeChildren( String name, Namespace ns ) { return element.removeChildren( name, ns ); } /** * @see org.jdom.Element#removeChildren(java.lang.String) */ public boolean removeChildren( String name ) { return element.removeChildren( name ); } /** * @see org.jdom.Element#removeContent() */ public List removeContent() { return element.removeContent(); } /** * @see org.jdom.Element#removeContent(org.jdom.Content) */ public boolean removeContent( Content child ) { return element.removeContent( child ); } /** * @see org.jdom.Element#removeContent(org.jdom.filter.Filter) */ public List removeContent( Filter filter ) { return element.removeContent( filter ); } /** * @see org.jdom.Element#removeContent(int) */ public Content removeContent( int index ) { return element.removeContent( index ); } /** * @see org.jdom.Element#removeNamespaceDeclaration(org.jdom.Namespace) */ public void removeNamespaceDeclaration( Namespace additionalNamespace ) { element.removeNamespaceDeclaration( additionalNamespace ); } /** * @see org.jdom.Element#setAttribute(org.jdom.Attribute) */ public Element setAttribute( Attribute attribute ) { return element.setAttribute( attribute ); } /** * @see org.jdom.Element#setAttribute(java.lang.String,java.lang.String,org.jdom.Namespace) */ public Element setAttribute( String name, String value, Namespace ns ) { return element.setAttribute( name, value, ns ); } /** * @see org.jdom.Element#setAttribute(java.lang.String,java.lang.String) */ public Element setAttribute( String name, String value ) { return element.setAttribute( name, value ); } /** * @see org.jdom.Element#setAttributes(java.util.List) */ public Element setAttributes( List newAttributes ) { return element.setAttributes( newAttributes ); } /** * @see org.jdom.Element#setContent(java.util.Collection) */ public Element setContent( Collection newContent ) { return element.setContent( newContent ); } /** * @see org.jdom.Element#setContent(org.jdom.Content) */ public Element setContent( Content child ) { return element.setContent( child ); } /** * @see org.jdom.Element#setContent(int,java.util.Collection) */ public Parent setContent( int index, Collection collection ) { return element.setContent( index, collection ); } /** * @see org.jdom.Element#setContent(int,org.jdom.Content) */ public Element setContent( int index, Content child ) { return element.setContent( index, child ); } /** * @see org.jdom.Element#setName(java.lang.String) */ public Element setName( String name ) { return element.setName( name ); } /** * @see org.jdom.Element#setNamespace(org.jdom.Namespace) */ public Element setNamespace( Namespace namespace ) { return element.setNamespace( namespace ); } /** * @see org.jdom.Element#setText(java.lang.String) */ public Element setText( String text ) { return element.setText( text ); } /** * @see org.jdom.Element#toString() */ public String toString() { return element.toString(); } /** * Returns the wrapped up JDom {@link Element} instance. */ public Element getElement() { return this.element; } /** * Sub classes should override if they wish to provide a different * combination of composite keys for determining conflicts. */ protected List getElementNamesForConflictResolution( List defaultList ) { return defaultList; } /** * Returns the default {@link MergeStrategy} instance. */ protected MergeStrategy getDefaultMergeStrategy() { return DEFAULT_MERGE_STRATEGY; } } ././@LongLink0000000000000000000000000000020300000000000011560 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/AbstractMergeableElementList.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Abs0000644000175000017500000002064411054033060033405 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.codehaus.plexus.metadata.merge.MergeException; import org.jdom.Element; /** * Base class that allows for handling merging two element lists. *

* TODO Refactor and make this extend {@link AbstractMergeableElement} which is what * this actually is, but with added bits for merging child element lists. * * @author Rahul Thakur * @version $Id: AbstractMergeableElementList.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public abstract class AbstractMergeableElementList extends AbstractMergeableElement { public AbstractMergeableElementList( Element element ) { super( element ); } /** * Parses <component> elements and builds a map keyed basd on the list of composite keys specified. * * @param tagName Name of the tag that appears multiple times * @param compositeKeyList List of element/tag names to be used as composite keys to register recurring * {@link Mergeable} instances. * @return Map of {@link Mergeable} instances keyed on the composite key obtained from * {@link #getElementNamesForConflictResolution(java.util.List)} * @throws Exception if there was an error parsing and registering {@link Mergeable} instances */ protected Map parseRecurringMergeables( String tagName, List compositeKeyList, Mergeable parentElement ) throws Exception { Map mergeables = new LinkedHashMap(); List list = this.getChildren( tagName ); for ( Iterator it = list.iterator(); it.hasNext(); ) { Element ce = (Element) it.next(); // use the composite key specified by the passed in list String compositeKey = ""; for ( Iterator itr = compositeKeyList.iterator(); itr.hasNext(); ) { String key = (String) itr.next(); if ( null != ce.getChildText( key ) ) { compositeKey = compositeKey + ce.getChildText( key ); } } // create a Mergeable instance and store it in the map. DescriptorTag tag = lookupTagInstanceByName( tagName, parentElement.getAllowedTags() ); Mergeable mergeable = tag.createMergeable( ce ); // register the Mergeable instance based on composite key mergeables.put( compositeKey, mergeable ); } return mergeables; } /** * Looks up and returns an {@link DescriptorTag} instance for the * specified tag name. * * @param name key to look up the {@link DescriptorTag} instance on. * @return {@link DescriptorTag} instance whose name matches the name specified. * Returns null if no match is found. */ private DescriptorTag lookupTagInstanceByName( String name, DescriptorTag[] values ) { DescriptorTag value = null; for ( int i = 0; i < values.length && value == null; i++ ) { if ( values[i].getTagName().equals( name ) ) { value = values[i]; } } // not found! return value; } public void merge( Mergeable me ) throws MergeException { try { Map dRequirementsMap = parseRecurringMergeables( getTagNameForRecurringMergeable(), getElementNamesForConflictResolution( new ArrayList() ), me ); Map rRequirementsMap = ( (AbstractMergeableElementList) me ) .parseRecurringMergeables( getTagNameForRecurringMergeable(), getElementNamesForConflictResolution( new ArrayList() ), me ); merge( getElement(), dRequirementsMap, rRequirementsMap ); } catch ( Exception e ) { // TODO: log to error // TODO: better error message throw new MergeException( "Unable to merge Mergeable lists for element '" + getName() + "'.", e ); } } /** * Identifies the conflicting elements in the dominant and recessive * {@link Map} instance and merges as required. * * @param parent {@link Element} that is parent for the children in the dominant Map instance. Merged content is * added to this element. * @param dMap Dominant Map keyed by the composite key obtained from * {@link #getElementNamesForConflictResolution(List)} * @param rMap Recessive Map keyed by the composite key obtained from * {@link #getElementNamesForConflictResolution(List)} * @throws Exception if there was an error merging both the maps. */ protected void merge( Element parent, Map dMap, Map rMap ) throws Exception { Set dKeySet = dMap.keySet(); Set rKeySet = rMap.keySet(); // check if there are any entities to merge if ( !isMergeRequired( dKeySet, rKeySet ) ) { return; } // iterate over components and process them for ( Iterator it = dKeySet.iterator(); it.hasNext(); ) { String dKey = (String) it.next(); if ( rMap.containsKey( dKey ) ) { // conflict ! merge this component Mergeable dMeregeable = (Mergeable) dMap.get( dKey ); Mergeable rMergeable = (Mergeable) rMap.get( dKey ); dMeregeable.merge( rMergeable ); // and remove from the recessive list to mark it as merged. rMap.remove( dKey ); } } // check if any unmerged components are left in the recessive map. if ( rMap.keySet().size() > 0 ) { // add them to results for ( Iterator it = rKeySet.iterator(); it.hasNext(); ) { String rKey = (String) it.next(); // add to parent parent.addContent( (Element) ( (Mergeable) rMap.get( rKey ) ).getElement().clone() ); } } } /** * Determines if a merge operation is required for the two sets (dominant and recessive) specified. * * @param dKeySet the dominant set of elements. * @param rKeySet the recessive set of elements. * @return true if a merge operation was required. */ private boolean isMergeRequired( Set dKeySet, Set rKeySet ) { return ( dKeySet.size() > 0 || rKeySet.size() > 0 ); } /** * Allows the sub classes to provided a tag name that they expect to recurr * within them. *

* For instance:
*

    *
  • <components> expects <component> to recurr within * itself.
  • *
  • <requirements> expects <requirement> to recurr within * itself.
  • *
* * @return tag name of the {@link Mergeable} element that occurs multiple times. */ protected abstract String getTagNameForRecurringMergeable(); protected abstract List getElementNamesForConflictResolution( List defaultList ); } ././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/DescriptorTag.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Des0000644000175000017500000001200011054033060033376 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * ======================================================================== * * Copyright 2003 The Apache Software Foundation. Code from this file * was originally imported from the Jakarta Cactus project. * * Copyright 2004-2006 Vincent Massol. * * Licensed 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.lang.reflect.Constructor; import org.jdom.Element; /** * Represents the various top-level tags in a deployment descriptor as a typesafe enumeration. * * @version $Id: DescriptorTag.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class DescriptorTag { /** * The tag name. */ private String tagName; /** * Whether multiple occurrences of the tag in the descriptor are allowed. */ private boolean multipleAllowed; /** * Class that wraps this tag and provides for merging same tags. */ private Class mergeableClass; /** * Constructor. * * @param tagName The tag name of the element */ public DescriptorTag( String tagName ) { this( tagName, false, null ); } /** * Constructor. * * @param tagName The tag name of the element * @param isMultipleAllowed Whether the element may occur multiple times in the descriptor * @deprecated Use {@link #DescriptorTag(String,boolean,Class)} instead */ public DescriptorTag( String tagName, boolean isMultipleAllowed ) { this( tagName, isMultipleAllowed, null ); } /** * Constructor. * * @param tagName The tag name of the element * @param isMultipleAllowed Whether the element may occur multiple times in the descriptor * @param mergeableClass Concrete implementation of {@link Mergeable} that is bound this tag. */ public DescriptorTag( String tagName, boolean isMultipleAllowed, Class mergeableClass ) { this.tagName = tagName; this.multipleAllowed = isMultipleAllowed; this.mergeableClass = mergeableClass; } public boolean equals( Object other ) { boolean eq = false; if ( other instanceof DescriptorTag ) { DescriptorTag tag = (DescriptorTag) other; if ( tag.getTagName().equals( this.tagName ) ) { eq = true; } } return eq; } public int hashCode() { return this.getTagName().hashCode(); } public String getTagName() { return this.tagName; } /** * Returns whether the tag may occur multiple times in the descriptor. * * @return Whether multiple occurrences are allowed */ public boolean isMultipleAllowed() { return this.multipleAllowed; } /** * Determines if a particular Tag is mergeable or not. *

* Basically means if we have a {@link Mergeable} class registered for a tag instance. * * @return true if this tag is mergeable. */ public boolean isMergeable() { return null != this.mergeableClass; } public String toString() { return getTagName(); } /** * Creates an {@link Mergeable} instance from the registered class for this * tag instance. * * @return instance of {@link Mergeable}. * @throws Exception if there was an error creating an instance. */ public Mergeable createMergeable( Element element ) throws Exception { Constructor cons = this.mergeableClass.getConstructor( new Class[] { Element.class } ); // XXX Is there a better way to determine this? if ( this.mergeableClass.getSuperclass().equals( AbstractMergeableElementList.class ) ) { return (AbstractMergeableElementList) cons.newInstance( new Object[] { element } ); } else if ( this.mergeableClass.getSuperclass().equals( AbstractMergeableElement.class ) ) { return (AbstractMergeableElement) cons.newInstance( new Object[] { element } ); } else { // TODO set up Logger // if (getLogger ().isErrorEnabled ()) // getLogger.error ( "Could not create Mergeable instance for specified class '" + this.mergeableClass + "'" ); throw new Exception( "Could not create Mergeable instance for specified class " + "'" + this.mergeableClass + "'" ); } } } ././@LongLink0000000000000000000000000000016700000000000011571 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/ComponentElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Com0000644000175000017500000000533611054033060033417 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: ComponentElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ComponentElement extends AbstractMergeableElement { /** * Allowed elements/tags that we can expect under this element. */ private final DescriptorTag[] allowedTags = { ROLE, ROLE_HINT, IMPLEMENTATION, FIELD_NAME, LIFECYCLE_HANDLER, DESCRIPTION, CONFIGURATION, RequirementsElement.TAG }; static final DescriptorTag TAG = new DescriptorTag( "component", true, ComponentElement.class ); static final DescriptorTag ROLE = new DescriptorTag( "role" ); static final DescriptorTag ROLE_HINT = new DescriptorTag( "role-hint" ); private static final DescriptorTag DESCRIPTION = new DescriptorTag( "description" ); private static final DescriptorTag CONFIGURATION = new DescriptorTag( "configuration" ); static final DescriptorTag FIELD_NAME = new DescriptorTag( "field-name" ); private static final DescriptorTag IMPLEMENTATION = new DescriptorTag( "implementation" ); private static final DescriptorTag LIFECYCLE_HANDLER = new DescriptorTag( "lifecycle-handler", false, null ); public ComponentElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ComponentElement; } public DescriptorTag[] getAllowedTags() { return allowedTags; } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/ConfigurationElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Con0000644000175000017500000000344211054033060033414 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.jdom.Element; /** * TODO Implement merge for this. * * @author Rahul Thakur * @version $Id: ConfigurationElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class ConfigurationElement extends AbstractMergeableElement { public ConfigurationElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof ConfigurationElement; } public DescriptorTag[] getAllowedTags() { // TODO Implement! return new DescriptorTag[0]; } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/RequirementsElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Req0000644000175000017500000000475711054033060033436 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.util.ArrayList; import java.util.List; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: RequirementsElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class RequirementsElement extends AbstractMergeableElementList { public static final DescriptorTag TAG = new DescriptorTag( "requirements", true, RequirementsElement.class ); public RequirementsElement( Element element ) { super( element ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof RequirementsElement; } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{RequirementElement.TAG}; } protected List getElementNamesForConflictResolution( List defaultList ) { // we return the keys that we know we want to lookup to identify and // resolve conflicts. List l = new ArrayList(); l.add( ComponentElement.ROLE.getTagName() ); // TODO: add this back, but a test will fail (based on a role with no hint, which shouldn't be legal) // l.add( ComponentElement.ROLE_HINT.getTagName() ); return l; } protected String getTagNameForRecurringMergeable() { return RequirementElement.TAG.getTagName(); } } ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/RequirementElement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/support/Req0000644000175000017500000000407111054033060033423 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge.support; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.metadata.merge.MergeException; import org.jdom.Element; /** * @author Rahul Thakur * @version $Id: RequirementElement.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class RequirementElement extends AbstractMergeableElement { static final DescriptorTag TAG = new DescriptorTag( "requirement", true, RequirementElement.class ); public RequirementElement( Element element ) { super( element ); } public DescriptorTag[] getAllowedTags() { return new DescriptorTag[]{ComponentElement.ROLE, ComponentElement.ROLE_HINT, ComponentElement.FIELD_NAME}; } public void merge( Mergeable me ) throws MergeException { super.merge( me ); } protected boolean isExpectedElementType( Mergeable me ) { return me instanceof RequirementElement; } } ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/PlexusXmlMerger.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/PlexusXmlMe0000644000175000017500000000465211202040413033403 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.metadata.merge.support.PlexusRootElement; import org.jdom.Document; /** * Plexus XML merger. This is a superset of the components xml merger so can be used in its place if necessary. * * @author Rahul Thakur * @version $Id: PlexusXmlMerger.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ @Component(role=Merger.class,hint="plexusXml") public class PlexusXmlMerger extends AbstractMerger { /** * @see org.codehaus.plexus.metadata.merge.Merger#merge(org.jdom.Document, org.jdom.Document) */ public Document merge( Document dDocument, Document rDocument ) throws MergeException { // TODO: Ideally we don't want to manipulate the original // dominant document but use its copy for merge. //Document mDoc = (Document) dDocument.clone(); // doesn't merge properly Document mDoc = dDocument; PlexusRootElement dCSE = new PlexusRootElement( mDoc.getRootElement() ); PlexusRootElement rCSE = new PlexusRootElement( rDocument.getRootElement() ); dCSE.merge( rCSE ); // the contents are merged into the dominant document DOM. return mDoc; } } ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MXParser.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MXParser.ja0000644000175000017500000040342311202040413033251 0ustar twernertwerner/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ /* * Copyright (c) 2003 Extreme! Lab, Indiana University. All rights reserved. * * This software is open source. See the bottom of this file for the licence. * * $Id: MXParser.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ package org.codehaus.plexus.metadata.merge; import java.io.EOFException; import java.io.IOException; import java.io.Reader; import java.io.UnsupportedEncodingException; import org.codehaus.plexus.util.ReaderFactory; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; //import java.util.Hashtable; //TODO best handling of interning issues // have isAllNewStringInterned ??? //TODO handling surrogate pairs: http://www.unicode.org/unicode/faq/utf_bom.html#6 //TODO review code for use of bufAbsoluteStart when keeping pos between next()/fillBuf() /** * Absolutely minimal implementation of XMLPULL V1 API. Encoding handling done with XmlReader * * @see org.codehaus.plexus.util.xml.XmlReader * @author Aleksander Slominski */ public class MXParser implements XmlPullParser { //NOTE: no interning of those strings --> by Java leng spec they MUST be already interned protected final static String XML_URI = "http://www.w3.org/XML/1998/namespace"; protected final static String XMLNS_URI = "http://www.w3.org/2000/xmlns/"; protected final static String FEATURE_XML_ROUNDTRIP= //"http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; "http://xmlpull.org/v1/doc/features.html#xml-roundtrip"; protected final static String FEATURE_NAMES_INTERNED = "http://xmlpull.org/v1/doc/features.html#names-interned"; protected final static String PROPERTY_XMLDECL_VERSION = "http://xmlpull.org/v1/doc/properties.html#xmldecl-version"; protected final static String PROPERTY_XMLDECL_STANDALONE = "http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone"; protected final static String PROPERTY_XMLDECL_CONTENT = "http://xmlpull.org/v1/doc/properties.html#xmldecl-content"; protected final static String PROPERTY_LOCATION = "http://xmlpull.org/v1/doc/properties.html#location"; protected final static String REPORT_NAMESPACE_PREFIXES = "http://xmlpull.org/v1/doc/features.html#report-namespace-prefixes"; /** * Implementation notice: * the is instance variable that controls if newString() is interning. *

NOTE: newStringIntern always returns interned strings * and newString MAY return interned String depending on this variable. *

NOTE: by default in this minimal implementation it is false! */ protected boolean allStringsInterned; protected boolean usePC; protected boolean seenStartTag; protected boolean seenEndTag; protected boolean pastEndTag; protected boolean seenAmpersand; protected boolean seenMarkup; protected boolean seenDocdecl; // transient variable set during each call to next/Token() protected boolean tokenize; protected String text; protected String entityRefName; protected String xmlDeclVersion; protected Boolean xmlDeclStandalone; protected String xmlDeclContent; // NOTE: features are not resetable and typically defaults to false ... protected boolean processNamespaces; protected boolean roundtripSupported; // global parser state protected String location; protected int lineNumber; protected int columnNumber; protected boolean seenRoot; protected boolean reachedEnd; protected int eventType; protected boolean emptyElementTag; // element stack protected int depth; protected char[] elRawName[]; protected int elRawNameEnd[]; protected int elRawNameLine[]; protected String elName[]; protected String elPrefix[]; protected String elUri[]; //protected String elValue[]; protected int elNamespaceCount[]; // input buffer management protected static final int READ_CHUNK_SIZE = 8*1024; //max data chars in one read() call protected Reader reader; protected String inputEncoding; protected int bufLoadFactor = 95; // 99% //protected int bufHardLimit; // only matters when expanding protected char buf[] = new char[READ_CHUNK_SIZE]; protected int bufSoftLimit = ( bufLoadFactor * buf.length ) /100; protected boolean preventBufferCompaction; protected int bufAbsoluteStart; // this is buf protected int bufStart; protected int bufEnd; protected int pos; protected int posStart; protected int posEnd; protected char pc[] = new char[READ_CHUNK_SIZE]; protected int pcStart; protected int pcEnd; protected void resetStringCache() { //System.out.println("resetStringCache() minimum called"); } protected String newString(char[] cbuf, int off, int len) { return new String(cbuf, off, len); } protected String newStringIntern(char[] cbuf, int off, int len) { return (new String(cbuf, off, len)).intern(); } private static final boolean TRACE_SIZING = false; /** * Make sure that we have enough space to keep element stack if passed size. * It will always create one additional slot then current depth */ protected void ensureElementsCapacity() { final int elStackSize = elName != null ? elName.length : 0; if( (depth + 1) >= elStackSize) { // we add at least one extra slot ... final int newSize = (depth >= 7 ? 2 * depth : 8) + 2; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING elStackSize "+elStackSize+" ==> "+newSize); } final boolean needsCopying = elStackSize > 0; String[] arr = null; // resue arr local variable slot arr = new String[newSize]; if(needsCopying) System.arraycopy(elName, 0, arr, 0, elStackSize); elName = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(elPrefix, 0, arr, 0, elStackSize); elPrefix = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(elUri, 0, arr, 0, elStackSize); elUri = arr; int[] iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elNamespaceCount, 0, iarr, 0, elStackSize); } else { // special initialization iarr[0] = 0; } elNamespaceCount = iarr; //TODO: avoid using element raw name ... iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elRawNameEnd, 0, iarr, 0, elStackSize); } elRawNameEnd = iarr; iarr = new int[newSize]; if(needsCopying) { System.arraycopy(elRawNameLine, 0, iarr, 0, elStackSize); } elRawNameLine = iarr; final char[][] carr = new char[newSize][]; if(needsCopying) { System.arraycopy(elRawName, 0, carr, 0, elStackSize); } elRawName = carr; // arr = new String[newSize]; // if(needsCopying) System.arraycopy(elLocalName, 0, arr, 0, elStackSize); // elLocalName = arr; // arr = new String[newSize]; // if(needsCopying) System.arraycopy(elDefaultNs, 0, arr, 0, elStackSize); // elDefaultNs = arr; // int[] iarr = new int[newSize]; // if(needsCopying) System.arraycopy(elNsStackPos, 0, iarr, 0, elStackSize); // for (int i = elStackSize; i < iarr.length; i++) // { // iarr[i] = (i > 0) ? -1 : 0; // } // elNsStackPos = iarr; //assert depth < elName.length; } } // attribute stack protected int attributeCount; protected String attributeName[]; protected int attributeNameHash[]; //protected int attributeNameStart[]; //protected int attributeNameEnd[]; protected String attributePrefix[]; protected String attributeUri[]; protected String attributeValue[]; //protected int attributeValueStart[]; //protected int attributeValueEnd[]; /** * Make sure that in attributes temporary array is enough space. */ protected void ensureAttributesCapacity(int size) { final int attrPosSize = attributeName != null ? attributeName.length : 0; if(size >= attrPosSize) { final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING attrPosSize "+attrPosSize+" ==> "+newSize); } final boolean needsCopying = attrPosSize > 0; String[] arr = null; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeName, 0, arr, 0, attrPosSize); attributeName = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributePrefix, 0, arr, 0, attrPosSize); attributePrefix = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeUri, 0, arr, 0, attrPosSize); attributeUri = arr; arr = new String[newSize]; if(needsCopying) System.arraycopy(attributeValue, 0, arr, 0, attrPosSize); attributeValue = arr; if( ! allStringsInterned ) { final int[] iarr = new int[newSize]; if(needsCopying) System.arraycopy(attributeNameHash, 0, iarr, 0, attrPosSize); attributeNameHash = iarr; } arr = null; // //assert attrUri.length > size } } // namespace stack protected int namespaceEnd; protected String namespacePrefix[]; protected int namespacePrefixHash[]; protected String namespaceUri[]; protected void ensureNamespacesCapacity(int size) { final int namespaceSize = namespacePrefix != null ? namespacePrefix.length : 0; if(size >= namespaceSize) { final int newSize = size > 7 ? 2 * size : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING namespaceSize "+namespaceSize+" ==> "+newSize); } final String[] newNamespacePrefix = new String[newSize]; final String[] newNamespaceUri = new String[newSize]; if(namespacePrefix != null) { System.arraycopy( namespacePrefix, 0, newNamespacePrefix, 0, namespaceEnd); System.arraycopy( namespaceUri, 0, newNamespaceUri, 0, namespaceEnd); } namespacePrefix = newNamespacePrefix; namespaceUri = newNamespaceUri; if( ! allStringsInterned ) { final int[] newNamespacePrefixHash = new int[newSize]; if(namespacePrefixHash != null) { System.arraycopy( namespacePrefixHash, 0, newNamespacePrefixHash, 0, namespaceEnd); } namespacePrefixHash = newNamespacePrefixHash; } //prefixesSize = newSize; // //assert nsPrefixes.length > size && nsPrefixes.length == newSize } } /** * simplistic implementation of hash function that has constant * time to compute - so it also means diminishing hash quality for long strings * but for XML parsing it should be good enough ... */ protected static final int fastHash( char ch[], int off, int len ) { if(len == 0) return 0; //assert len >0 int hash = ch[off]; // hash at beginning //try { hash = (hash << 7) + ch[ off + len - 1 ]; // hash at the end //} catch(ArrayIndexOutOfBoundsException aie) { // aie.printStackTrace(); //should never happen ... // throw new RuntimeException("this is violation of pre-condition"); //} if(len > 16) hash = (hash << 7) + ch[ off + (len / 4)]; // 1/4 from beginning if(len > 8) hash = (hash << 7) + ch[ off + (len / 2)]; // 1/2 of string size ... // notice that hash is at most done 3 times <<7 so shifted by 21 bits 8 bit value // so max result == 29 bits so it is quite just below 31 bits for long (2^32) ... //assert hash >= 0; return hash; } // entity replacement stack protected int entityEnd; protected String entityName[]; protected char[] entityNameBuf[]; protected String entityReplacement[]; protected char[] entityReplacementBuf[]; protected int entityNameHash[]; protected void ensureEntityCapacity() { final int entitySize = entityReplacementBuf != null ? entityReplacementBuf.length : 0; if(entityEnd >= entitySize) { final int newSize = entityEnd > 7 ? 2 * entityEnd : 8; // = lucky 7 + 1 //25 if(TRACE_SIZING) { System.err.println("TRACE_SIZING entitySize "+entitySize+" ==> "+newSize); } final String[] newEntityName = new String[newSize]; final char[] newEntityNameBuf[] = new char[newSize][]; final String[] newEntityReplacement = new String[newSize]; final char[] newEntityReplacementBuf[] = new char[newSize][]; if(entityName != null) { System.arraycopy(entityName, 0, newEntityName, 0, entityEnd); System.arraycopy(entityNameBuf, 0, newEntityNameBuf, 0, entityEnd); System.arraycopy(entityReplacement, 0, newEntityReplacement, 0, entityEnd); System.arraycopy(entityReplacementBuf, 0, newEntityReplacementBuf, 0, entityEnd); } entityName = newEntityName; entityNameBuf = newEntityNameBuf; entityReplacement = newEntityReplacement; entityReplacementBuf = newEntityReplacementBuf; if( ! allStringsInterned ) { final int[] newEntityNameHash = new int[newSize]; if(entityNameHash != null) { System.arraycopy(entityNameHash, 0, newEntityNameHash, 0, entityEnd); } entityNameHash = newEntityNameHash; } } } protected void reset() { location = null; lineNumber = 1; columnNumber = 0; seenRoot = false; reachedEnd = false; eventType = START_DOCUMENT; emptyElementTag = false; depth = 0; attributeCount = 0; namespaceEnd = 0; entityEnd = 0; reader = null; inputEncoding = null; preventBufferCompaction = false; bufAbsoluteStart = 0; bufEnd = bufStart = 0; pos = posStart = posEnd = 0; pcEnd = pcStart = 0; usePC = false; seenStartTag = false; seenEndTag = false; pastEndTag = false; seenAmpersand = false; seenMarkup = false; seenDocdecl = false; xmlDeclVersion = null; xmlDeclStandalone = null; xmlDeclContent = null; resetStringCache(); } public MXParser() { } /** * Method setFeature * * @param name a String * @param state a boolean * * @throws XmlPullParserException * */ public void setFeature(String name, boolean state) throws XmlPullParserException { if(name == null) throw new IllegalArgumentException("feature name should not be null"); if(FEATURE_PROCESS_NAMESPACES.equals(name)) { if(eventType != START_DOCUMENT) throw new XmlPullParserException( "namespace processing feature can only be changed before parsing", this, null); processNamespaces = state; // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { // if(type != START_DOCUMENT) throw new XmlPullParserException( // "namespace reporting feature can only be changed before parsing", this, null); // reportNsAttribs = state; } else if(FEATURE_NAMES_INTERNED.equals(name)) { if(state != false) { throw new XmlPullParserException( "interning names in this implementation is not supported"); } } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { if(state != false) { throw new XmlPullParserException( "processing DOCDECL is not supported"); } //} else if(REPORT_DOCDECL.equals(name)) { // paramNotifyDoctype = state; } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { //if(state == false) { // throw new XmlPullParserException( // "roundtrip feature can not be switched off"); //} roundtripSupported = state; } else { throw new XmlPullParserException("unsupporte feature "+name); } } /** Unknown properties are always returned as false */ public boolean getFeature(String name) { if(name == null) throw new IllegalArgumentException("feature name should not be nulll"); if(FEATURE_PROCESS_NAMESPACES.equals(name)) { return processNamespaces; // } else if(FEATURE_REPORT_NAMESPACE_ATTRIBUTES.equals(name)) { // return reportNsAttribs; } else if(FEATURE_NAMES_INTERNED.equals(name)) { return false; } else if(FEATURE_PROCESS_DOCDECL.equals(name)) { return false; //} else if(REPORT_DOCDECL.equals(name)) { // return paramNotifyDoctype; } else if(FEATURE_XML_ROUNDTRIP.equals(name)) { //return true; return roundtripSupported; } else if( REPORT_NAMESPACE_PREFIXES.equals( name ) ) { return processNamespaces; } return false; } public void setProperty(String name, Object value) throws XmlPullParserException { if(PROPERTY_LOCATION.equals(name)) { location = (String) value; } else { throw new XmlPullParserException("unsupported property: '"+name+"'"); } } public Object getProperty(String name) { if(name == null) throw new IllegalArgumentException("property name should not be nulll"); if(PROPERTY_XMLDECL_VERSION.equals(name)) { return xmlDeclVersion; } else if(PROPERTY_XMLDECL_STANDALONE.equals(name)) { return xmlDeclStandalone; } else if(PROPERTY_XMLDECL_CONTENT.equals(name)) { return xmlDeclContent; } else if(PROPERTY_LOCATION.equals(name)) { return location; } return null; } public void setInput(Reader in) throws XmlPullParserException { reset(); reader = in; } public void setInput(java.io.InputStream inputStream, String inputEncoding) throws XmlPullParserException { if(inputStream == null) { throw new IllegalArgumentException("input stream can not be null"); } Reader reader; try { if(inputEncoding != null) { reader = ReaderFactory.newReader(inputStream, inputEncoding); } else { reader = ReaderFactory.newXmlReader(inputStream); } } catch (UnsupportedEncodingException une) { throw new XmlPullParserException( "could not create reader for encoding "+inputEncoding+" : "+une, this, une); } catch ( IOException e ) { throw new XmlPullParserException( "could not create reader : "+e, this, e); } setInput(reader); //must be here as reset() was called in setInput() and has set this.inputEncoding to null ... this.inputEncoding = inputEncoding; } public String getInputEncoding() { return inputEncoding; } public void defineEntityReplacementText(String entityName, String replacementText) throws XmlPullParserException { // throw new XmlPullParserException("not allowed"); //protected char[] entityReplacement[]; ensureEntityCapacity(); // this is to make sure that if interning works we will take advantage of it ... this.entityName[entityEnd] = newString(entityName.toCharArray(), 0, entityName.length()); entityNameBuf[entityEnd] = entityName.toCharArray(); entityReplacement[entityEnd] = replacementText; entityReplacementBuf[entityEnd] = replacementText.toCharArray(); if(!allStringsInterned) { entityNameHash[ entityEnd ] = fastHash(entityNameBuf[entityEnd], 0, entityNameBuf[entityEnd].length); } ++entityEnd; //TODO disallow < or & in entity replacement text (or ]]>???) // TOOD keepEntityNormalizedForAttributeValue cached as well ... } public int getNamespaceCount(int depth) throws XmlPullParserException { if(processNamespaces == false || depth == 0) { return 0; } //int maxDepth = eventType == END_TAG ? this.depth + 1 : this.depth; //if(depth < 0 || depth > maxDepth) throw new IllegalArgumentException( if(depth < 0 || depth > this.depth) throw new IllegalArgumentException( "napespace count mayt be for depth 0.."+this.depth+" not "+depth); return elNamespaceCount[ depth ]; } public String getNamespacePrefix(int pos) throws XmlPullParserException { //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; //if(pos < end) { if(pos < namespaceEnd) { return namespacePrefix[ pos ]; } else { throw new XmlPullParserException( "position "+pos+" exceeded number of available namespaces "+namespaceEnd); } } public String getNamespaceUri(int pos) throws XmlPullParserException { //int end = eventType == END_TAG ? elNamespaceCount[ depth + 1 ] : namespaceEnd; //if(pos < end) { if(pos < namespaceEnd) { return namespaceUri[ pos ]; } else { throw new XmlPullParserException( "position "+pos+" exceedded number of available namespaces "+namespaceEnd); } } public String getNamespace( String prefix ) //throws XmlPullParserException { //int count = namespaceCount[ depth ]; if(prefix != null) { for( int i = namespaceEnd -1; i >= 0; i--) { if( prefix.equals( namespacePrefix[ i ] ) ) { return namespaceUri[ i ]; } } if("xml".equals( prefix )) { return XML_URI; } else if("xmlns".equals( prefix )) { return XMLNS_URI; } } else { for( int i = namespaceEnd -1; i >= 0; i--) { if( namespacePrefix[ i ] == null) { //"") { //null ) { //TODO check FIXME Alek return namespaceUri[ i ]; } } } return null; } public int getDepth() { return depth; } private static int findFragment(int bufMinPos, char[] b, int start, int end) { //System.err.println("bufStart="+bufStart+" b="+printable(new String(b, start, end - start))+" start="+start+" end="+end); if(start < bufMinPos) { start = bufMinPos; if(start > end) start = end; return start; } if(end - start > 65) { start = end - 10; // try to find good location } int i = start + 1; while(--i > bufMinPos) { if((end - i) > 65) break; final char c = b[i]; if(c == '<' && (start - i) > 10) break; } return i; } /** * Return string describing current position of parsers as * text 'STATE [seen %s...] @line:column'. */ public String getPositionDescription () { String fragment = null; if(posStart <= pos) { final int start = findFragment(0, buf, posStart, pos); //System.err.println("start="+start); if(start < pos) { fragment = new String(buf, start, pos - start); } if(bufAbsoluteStart > 0 || start > 0) fragment = "..." + fragment; } // return " at line "+tokenizerPosRow // +" and column "+(tokenizerPosCol-1) // +(fragment != null ? " seen "+printable(fragment)+"..." : ""); return " "+TYPES[ eventType ] + (fragment != null ? " seen "+printable(fragment)+"..." : "") +" "+(location != null ? location : "") +"@"+getLineNumber()+":"+getColumnNumber(); } public int getLineNumber() { return lineNumber; } public int getColumnNumber() { return columnNumber; } public boolean isWhitespace() throws XmlPullParserException { if(eventType == TEXT || eventType == CDSECT) { if(usePC) { for (int i = pcStart; i = 0; i--) { // if( prefix.equals( namespacePrefix[ i ] ) ) { // return namespaceUri[ i ]; // } // } // } else { // for( int i = namespaceEnd -1; i >= 0; i--) { // if( namespacePrefix[ i ] == null ) { // return namespaceUri[ i ]; // } // } // // } // return ""; } public String getName() { if(eventType == START_TAG) { //return elName[ depth - 1 ] ; return elName[ depth ] ; } else if(eventType == END_TAG) { return elName[ depth ] ; } else if(eventType == ENTITY_REF) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } return entityRefName; } else { return null; } } public String getPrefix() { if(eventType == START_TAG) { //return elPrefix[ depth - 1 ] ; return elPrefix[ depth ] ; } else if(eventType == END_TAG) { return elPrefix[ depth ] ; } return null; // if(eventType != START_TAG && eventType != END_TAG) return null; // int maxDepth = eventType == END_TAG ? depth : depth - 1; // return elPrefix[ maxDepth ]; } public boolean isEmptyElementTag() throws XmlPullParserException { if(eventType != START_TAG) throw new XmlPullParserException( "parser must be on START_TAG to check for empty element", this, null); return emptyElementTag; } public int getAttributeCount() { if(eventType != START_TAG) return -1; return attributeCount; } public String getAttributeNamespace(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(processNamespaces == false) return NO_NAMESPACE; if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeUri[ index ]; } public String getAttributeName(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeName[ index ]; } public String getAttributePrefix(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(processNamespaces == false) return null; if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributePrefix[ index ]; } public String getAttributeType(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return "CDATA"; } public boolean isAttributeDefault(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return false; } public String getAttributeValue(int index) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"); if(index < 0 || index >= attributeCount) throw new IndexOutOfBoundsException( "attribute position must be 0.."+(attributeCount-1)+" and not "+index); return attributeValue[ index ]; } public String getAttributeValue(String namespace, String name) { if(eventType != START_TAG) throw new IndexOutOfBoundsException( "only START_TAG can have attributes"+getPositionDescription()); if(name == null) { throw new IllegalArgumentException("attribute name can not be null"); } // TODO make check if namespace is interned!!! etc. for names!!! if(processNamespaces) { if(namespace == null) { namespace = ""; } for(int i = 0; i < attributeCount; ++i) { if((namespace == attributeUri[ i ] || namespace.equals(attributeUri[ i ]) ) //(namespace != null && namespace.equals(attributeUri[ i ])) // taking advantage of String.intern() && name.equals(attributeName[ i ]) ) { return attributeValue[i]; } } } else { if(namespace != null && namespace.length() == 0) { namespace = null; } if(namespace != null) throw new IllegalArgumentException( "when namespaces processing is disabled attribute namespace must be null"); for(int i = 0; i < attributeCount; ++i) { if(name.equals(attributeName[i])) { return attributeValue[i]; } } } return null; } public int getEventType() throws XmlPullParserException { return eventType; } public void require(int type, String namespace, String name) throws XmlPullParserException, IOException { if(processNamespaces == false && namespace != null) { throw new XmlPullParserException( "processing namespaces must be enabled on parser (or factory)"+ " to have possible namespaces delcared on elements" +(" (postion:"+ getPositionDescription())+")"); } if (type != getEventType() || (namespace != null && !namespace.equals (getNamespace())) || (name != null && !name.equals (getName ())) ) { throw new XmlPullParserException ( "expected event "+TYPES[ type ] +(name != null ? " with name '"+name+"'" : "") +(namespace != null && name != null ? " and" : "") +(namespace != null ? " with namespace '"+namespace+"'" : "") +" but got" +(type != getEventType() ? " "+TYPES[ getEventType() ] : "") +(name != null && getName() != null && !name.equals (getName ()) ? " name '"+getName()+"'" : "") +(namespace != null && name != null && getName() != null && !name.equals (getName ()) && getNamespace() != null && !namespace.equals (getNamespace()) ? " and" : "") +(namespace != null && getNamespace() != null && !namespace.equals (getNamespace()) ? " namespace '"+getNamespace()+"'" : "") +(" (postion:"+ getPositionDescription())+")"); } } /** * Skip sub tree that is currently porser positioned on. *
NOTE: parser must be on START_TAG and when funtion returns * parser will be positioned on corresponding END_TAG */ public void skipSubTree() throws XmlPullParserException, IOException { require(START_TAG, null, null); int level = 1; while(level > 0) { int eventType = next(); if(eventType == END_TAG) { --level; } else if(eventType == START_TAG) { ++level; } } } // public String readText() throws XmlPullParserException, IOException // { // if (getEventType() != TEXT) return ""; // String result = getText(); // next(); // return result; // } public String nextText() throws XmlPullParserException, IOException { // String result = null; // boolean onStartTag = false; // if(eventType == START_TAG) { // onStartTag = true; // next(); // } // if(eventType == TEXT) { // result = getText(); // next(); // } else if(onStartTag && eventType == END_TAG) { // result = ""; // } else { // throw new XmlPullParserException( // "parser must be on START_TAG or TEXT to read text", this, null); // } // if(eventType != END_TAG) { // throw new XmlPullParserException( // "event TEXT it must be immediately followed by END_TAG", this, null); // } // return result; if(getEventType() != START_TAG) { throw new XmlPullParserException( "parser must be on START_TAG to read next text", this, null); } int eventType = next(); if(eventType == TEXT) { final String result = getText(); eventType = next(); if(eventType != END_TAG) { throw new XmlPullParserException( "TEXT must be immediately followed by END_TAG and not " +TYPES[ getEventType() ], this, null); } return result; } else if(eventType == END_TAG) { return ""; } else { throw new XmlPullParserException( "parser must be on START_TAG or TEXT to read text", this, null); } } public int nextTag() throws XmlPullParserException, IOException { next(); if(eventType == TEXT && isWhitespace()) { // skip whitespace next(); } if (eventType != START_TAG && eventType != END_TAG) { throw new XmlPullParserException("expected START_TAG or END_TAG not " +TYPES[ getEventType() ], this, null); } return eventType; } public int next() throws XmlPullParserException, IOException { tokenize = false; return nextImpl(); } public int nextToken() throws XmlPullParserException, IOException { tokenize = true; return nextImpl(); } protected int nextImpl() throws XmlPullParserException, IOException { text = null; pcEnd = pcStart = 0; usePC = false; bufStart = posEnd; if(pastEndTag) { pastEndTag = false; --depth; namespaceEnd = elNamespaceCount[ depth ]; // less namespaces available } if(emptyElementTag) { emptyElementTag = false; pastEndTag = true; return eventType = END_TAG; } // [1] document ::= prolog element Misc* if(depth > 0) { if(seenStartTag) { seenStartTag = false; return eventType = parseStartTag(); } if(seenEndTag) { seenEndTag = false; return eventType = parseEndTag(); } // ASSUMPTION: we are _on_ first character of content or markup!!!! // [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* char ch; if(seenMarkup) { // we have read ahead ... seenMarkup = false; ch = '<'; } else if(seenAmpersand) { seenAmpersand = false; ch = '&'; } else { ch = more(); } posStart = pos - 1; // VERY IMPORTANT: this is correct start of event!!! // when true there is some potential event TEXT to return - keep gathering boolean hadCharData = false; // when true TEXT data is not continuous (like ) and requires PC merging boolean needsMerging = false; MAIN_LOOP: while(true) { // work on MARKUP if(ch == '<') { if(hadCharData) { //posEnd = pos - 1; if(tokenize) { seenMarkup = true; return eventType = TEXT; } } ch = more(); if(ch == '/') { if(!tokenize && hadCharData) { seenEndTag = true; //posEnd = pos - 2; return eventType = TEXT; } return eventType = parseEndTag(); } else if(ch == '!') { ch = more(); if(ch == '-') { // note: if(tokenize == false) posStart/End is NOT changed!!!! parseComment(); if(tokenize) return eventType = COMMENT; if( !usePC && hadCharData ) { needsMerging = true; } else { posStart = pos; //completely ignore comment } } else if(ch == '[') { //posEnd = pos - 3; // must remember previous posStart/End as it merges with content of CDATA //int oldStart = posStart + bufAbsoluteStart; //int oldEnd = posEnd + bufAbsoluteStart; parseCDSect(hadCharData); if(tokenize) return eventType = CDSECT; final int cdStart = posStart; final int cdEnd = posEnd; final int cdLen = cdEnd - cdStart; if(cdLen > 0) { // was there anything inside CDATA section? hadCharData = true; if(!usePC) { needsMerging = true; } } // posStart = oldStart; // posEnd = oldEnd; // if(cdLen > 0) { // was there anything inside CDATA section? // if(hadCharData) { // // do merging if there was anything in CDSect!!!! // // if(!usePC) { // // // posEnd is correct already!!! // // if(posEnd > posStart) { // // joinPC(); // // } else { // // usePC = true; // // pcStart = pcEnd = 0; // // } // // } // // if(pcEnd + cdLen >= pc.length) ensurePC(pcEnd + cdLen); // // // copy [cdStart..cdEnd) into PC // // System.arraycopy(buf, cdStart, pc, pcEnd, cdLen); // // pcEnd += cdLen; // if(!usePC) { // needsMerging = true; // posStart = cdStart; // posEnd = cdEnd; // } // } else { // if(!usePC) { // needsMerging = true; // posStart = cdStart; // posEnd = cdEnd; // hadCharData = true; // } // } // //hadCharData = true; // } else { // if( !usePC && hadCharData ) { // needsMerging = true; // } // } } else { throw new XmlPullParserException( "unexpected character in markup "+printable(ch), this, null); } } else if(ch == '?') { parsePI(); if(tokenize) return eventType = PROCESSING_INSTRUCTION; if( !usePC && hadCharData ) { needsMerging = true; } else { posStart = pos; //completely ignore PI } } else if( isNameStartChar(ch) ) { if(!tokenize && hadCharData) { seenStartTag = true; //posEnd = pos - 2; return eventType = TEXT; } return eventType = parseStartTag(); } else { throw new XmlPullParserException( "unexpected character in markup "+printable(ch), this, null); } // do content comapctation if it makes sense!!!! } else if(ch == '&') { // work on ENTITTY //posEnd = pos - 1; if(tokenize && hadCharData) { seenAmpersand = true; return eventType = TEXT; } final int oldStart = posStart + bufAbsoluteStart; final int oldEnd = posEnd + bufAbsoluteStart; final char[] resolvedEntity = parseEntityRef(); if(tokenize) return eventType = ENTITY_REF; // check if replacement text can be resolved !!! if(resolvedEntity == null) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } throw new XmlPullParserException( "could not resolve entity named '"+printable(entityRefName)+"'", this, null); } //int entStart = posStart; //int entEnd = posEnd; posStart = oldStart - bufAbsoluteStart; posEnd = oldEnd - bufAbsoluteStart; if(!usePC) { if(hadCharData) { joinPC(); // posEnd is already set correctly!!! needsMerging = false; } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; // write into PC replacement text - do merge for replacement text!!!! for (int i = 0; i < resolvedEntity.length; i++) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = resolvedEntity[ i ]; } hadCharData = true; //assert needsMerging == false; } else { if(needsMerging) { //assert usePC == false; joinPC(); // posEnd is already set correctly!!! //posStart = pos - 1; needsMerging = false; } //no MARKUP not ENTITIES so work on character data ... // [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) hadCharData = true; boolean normalizedCR = false; final boolean normalizeInput = tokenize == false || roundtripSupported == false; // use loop locality here!!!! boolean seenBracket = false; boolean seenBracketBracket = false; do { // check that ]]> does not show in if(ch == ']') { if(seenBracket) { seenBracketBracket = true; } else { seenBracket = true; } } else if(seenBracketBracket && ch == '>') { throw new XmlPullParserException( "characters ]]> are not allowed in content", this, null); } else { if(seenBracket) { seenBracketBracket = seenBracket = false; } // assert seenTwoBrackets == seenBracket == false; } if(normalizeInput) { // deal with normalization issues ... if(ch == '\r') { normalizedCR = true; posEnd = pos -1; // posEnd is already set if(!usePC) { if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { // if(!usePC) { joinPC(); } else { if(pcEnd >= pc.length) ensurePC(); } if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } ch = more(); } while(ch != '<' && ch != '&'); posEnd = pos - 1; continue MAIN_LOOP; // skip ch = more() from below - we are already ahead ... } ch = more(); } // endless while(true) } else { if(seenRoot) { return parseEpilog(); } else { return parseProlog(); } } } protected int parseProlog() throws XmlPullParserException, IOException { // [2] prolog: ::= XMLDecl? Misc* (doctypedecl Misc*)? and look for [39] element char ch; if(seenMarkup) { ch = buf[ pos - 1 ]; } else { ch = more(); } if(eventType == START_DOCUMENT) { // bootstrap parsing with getting first character input! // deal with BOM // detect BOM and crop it (Unicode int Order Mark) if(ch == '\uFFFE') { throw new XmlPullParserException( "first character in input was UNICODE noncharacter (0xFFFE)"+ "- input requires int swapping", this, null); } if(ch == '\uFEFF') { // skipping UNICODE int Order Mark (so called BOM) ch = more(); } } seenMarkup = false; boolean gotS = false; posStart = pos - 1; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; while(true) { // deal with Misc // [27] Misc ::= Comment | PI | S // deal with docdecl --> mark it! // else parseStartTag seen <[^/] if(ch == '<') { if(gotS && tokenize) { posEnd = pos - 1; seenMarkup = true; return eventType = IGNORABLE_WHITESPACE; } ch = more(); if(ch == '?') { // check if it is 'xml' // deal with XMLDecl boolean isXMLDecl = parsePI(); if(tokenize) { if (isXMLDecl) { return eventType = START_DOCUMENT; } return eventType = PROCESSING_INSTRUCTION; } } else if(ch == '!') { ch = more(); if(ch == 'D') { if(seenDocdecl) { throw new XmlPullParserException( "only one docdecl allowed in XML document", this, null); } seenDocdecl = true; parseDocdecl(); if(tokenize) return eventType = DOCDECL; } else if(ch == '-') { parseComment(); if(tokenize) return eventType = COMMENT; } else { throw new XmlPullParserException( "unexpected markup posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } else { throw new XmlPullParserException( "only whitespace content allowed before start tag and not "+printable(ch), this, null); } ch = more(); } } protected int parseEpilog() throws XmlPullParserException, IOException { if(eventType == END_DOCUMENT) { throw new XmlPullParserException("already reached end of XML input", this, null); } if(reachedEnd) { return eventType = END_DOCUMENT; } boolean gotS = false; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; try { // epilog: Misc* char ch; if(seenMarkup) { ch = buf[ pos - 1 ]; } else { ch = more(); } seenMarkup = false; posStart = pos - 1; if(!reachedEnd) { while(true) { // deal with Misc // [27] Misc ::= Comment | PI | S if(ch == '<') { if(gotS && tokenize) { posEnd = pos - 1; seenMarkup = true; return eventType = IGNORABLE_WHITESPACE; } ch = more(); if(reachedEnd) { break; } if(ch == '?') { // check if it is 'xml' // deal with XMLDecl parsePI(); if(tokenize) return eventType = PROCESSING_INSTRUCTION; } else if(ch == '!') { ch = more(); if(reachedEnd) { break; } if(ch == 'D') { parseDocdecl(); //FIXME if(tokenize) return eventType = DOCDECL; } else if(ch == '-') { parseComment(); if(tokenize) return eventType = COMMENT; } else { throw new XmlPullParserException( "unexpected markup posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } else { throw new XmlPullParserException( "in epilog non whitespace content is not allowed but got "+printable(ch), this, null); } ch = more(); if(reachedEnd) { break; } } } // throw Exception("unexpected content in epilog // catch EOFException return END_DOCUMENT //try { } catch(EOFException ex) { reachedEnd = true; } if(reachedEnd) { if(tokenize && gotS) { posEnd = pos; // well - this is LAST available character pos return eventType = IGNORABLE_WHITESPACE; } return eventType = END_DOCUMENT; } else { throw new XmlPullParserException("internal error in parseEpilog"); } } public int parseEndTag() throws XmlPullParserException, IOException { //ASSUMPTION ch is past "' char ch = more(); if(!isNameStartChar(ch)) { throw new XmlPullParserException( "expected name start and not "+printable(ch), this, null); } posStart = pos - 3; final int nameStart = pos - 1 + bufAbsoluteStart; do { ch = more(); } while(isNameChar(ch)); // now we go one level down -- do checks //--depth; //FIXME // check that end tag name is the same as start tag //String name = new String(buf, nameStart - bufAbsoluteStart, // (pos - 1) - (nameStart - bufAbsoluteStart)); //int last = pos - 1; int off = nameStart - bufAbsoluteStart; //final int len = last - off; final int len = (pos - 1) - off; final char[] cbuf = elRawName[depth]; if(elRawNameEnd[depth] != len) { // construct strings for exception final String startname = new String(cbuf, 0, elRawNameEnd[depth]); final String endname = new String(buf, off, len); throw new XmlPullParserException( "end tag name must match start tag name <"+startname+">" +" from line "+elRawNameLine[depth], this, null); } for (int i = 0; i < len; i++) { if(buf[off++] != cbuf[i]) { // construct strings for exception final String startname = new String(cbuf, 0, len); final String endname = new String(buf, off - i - 1, len); throw new XmlPullParserException( "end tag name must be the same as start tag <"+startname+">" +" from line "+elRawNameLine[depth], this, null); } } while(isS(ch)) { ch = more(); } // skip additional white spaces if(ch != '>') { throw new XmlPullParserException( "expected > to finsh end tag not "+printable(ch) +" from line "+elRawNameLine[depth], this, null); } //namespaceEnd = elNamespaceCount[ depth ]; //FIXME posEnd = pos; pastEndTag = true; return eventType = END_TAG; } public int parseStartTag() throws XmlPullParserException, IOException { //ASSUMPTION ch is past ' // [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' ++depth; //FIXME posStart = pos - 2; emptyElementTag = false; attributeCount = 0; // retrieve name final int nameStart = pos - 1 + bufAbsoluteStart; int colonPos = -1; char ch = buf[ pos - 1]; if(ch == ':' && processNamespaces) throw new XmlPullParserException( "when namespaces processing enabled colon can not be at element name start", this, null); while(true) { ch = more(); if(!isNameChar(ch)) break; if(ch == ':' && processNamespaces) { if(colonPos != -1) throw new XmlPullParserException( "only one colon is allowed in name of element when namespaces are enabled", this, null); colonPos = pos - 1 + bufAbsoluteStart; } } // retrieve name ensureElementsCapacity(); //TODO check for efficient interning and then use elRawNameInterned!!!! int elLen = (pos - 1) - (nameStart - bufAbsoluteStart); if(elRawName[ depth ] == null || elRawName[ depth ].length < elLen) { elRawName[ depth ] = new char[ 2 * elLen ]; } System.arraycopy(buf, nameStart - bufAbsoluteStart, elRawName[ depth ], 0, elLen); elRawNameEnd[ depth ] = elLen; elRawNameLine[ depth ] = lineNumber; String name = null; // work on prefixes and namespace URI String prefix = null; if(processNamespaces) { if(colonPos != -1) { prefix = elPrefix[ depth ] = newString(buf, nameStart - bufAbsoluteStart, colonPos - nameStart); name = elName[ depth ] = newString(buf, colonPos + 1 - bufAbsoluteStart, //(pos -1) - (colonPos + 1)); pos - 2 - (colonPos - bufAbsoluteStart)); } else { prefix = elPrefix[ depth ] = null; name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); } } else { name = elName[ depth ] = newString(buf, nameStart - bufAbsoluteStart, elLen); } while(true) { while(isS(ch)) { ch = more(); } // skip additional white spaces if(ch == '>') { break; } else if(ch == '/') { if(emptyElementTag) throw new XmlPullParserException( "repeated / in tag declaration", this, null); emptyElementTag = true; ch = more(); if(ch != '>') throw new XmlPullParserException( "expected > to end empty tag not "+printable(ch), this, null); break; } else if(isNameStartChar(ch)) { ch = parseAttribute(); ch = more(); continue; } else { throw new XmlPullParserException( "start tag unexpected character "+printable(ch), this, null); } //ch = more(); // skip space } // now when namespaces were declared we can resolve them if(processNamespaces) { String uri = getNamespace(prefix); if(uri == null) { if(prefix == null) { // no prefix and no uri => use default namespace uri = NO_NAMESPACE; } else { throw new XmlPullParserException( "could not determine namespace bound to element prefix "+prefix, this, null); } } elUri[ depth ] = uri; //String uri = getNamespace(prefix); //if(uri == null && prefix == null) { // no prefix and no uri => use default namespace // uri = ""; //} // resolve attribute namespaces for (int i = 0; i < attributeCount; i++) { final String attrPrefix = attributePrefix[ i ]; if(attrPrefix != null) { final String attrUri = getNamespace(attrPrefix); if(attrUri == null) { throw new XmlPullParserException( "could not determine namespace bound to attribute prefix "+attrPrefix, this, null); } attributeUri[ i ] = attrUri; } else { attributeUri[ i ] = NO_NAMESPACE; } } //TODO //[ WFC: Unique Att Spec ] // check namespaced attribute uniqueness contraint!!! for (int i = 1; i < attributeCount; i++) { for (int j = 0; j < i; j++) { if( attributeUri[j] == attributeUri[i] && (allStringsInterned && attributeName[j].equals(attributeName[i]) || (!allStringsInterned && attributeNameHash[ j ] == attributeNameHash[ i ] && attributeName[j].equals(attributeName[i])) ) ) { // prepare data for nice error messgae? String attr1 = attributeName[j]; if(attributeUri[j] != null) attr1 = attributeUri[j]+":"+attr1; String attr2 = attributeName[i]; if(attributeUri[i] != null) attr2 = attributeUri[i]+":"+attr2; throw new XmlPullParserException( "duplicated attributes "+attr1+" and "+attr2, this, null); } } } } else { // ! processNamespaces //[ WFC: Unique Att Spec ] // check raw attribute uniqueness contraint!!! for (int i = 1; i < attributeCount; i++) { for (int j = 0; j < i; j++) { if((allStringsInterned && attributeName[j].equals(attributeName[i]) || (!allStringsInterned && attributeNameHash[ j ] == attributeNameHash[ i ] && attributeName[j].equals(attributeName[i])) ) ) { // prepare data for nice error messgae? final String attr1 = attributeName[j]; final String attr2 = attributeName[i]; throw new XmlPullParserException( "duplicated attributes "+attr1+" and "+attr2, this, null); } } } } elNamespaceCount[ depth ] = namespaceEnd; posEnd = pos; return eventType = START_TAG; } protected char parseAttribute() throws XmlPullParserException, IOException { // parse attribute // [41] Attribute ::= Name Eq AttValue // [WFC: No External Entity References] // [WFC: No < in Attribute Values] final int prevPosStart = posStart + bufAbsoluteStart; final int nameStart = pos - 1 + bufAbsoluteStart; int colonPos = -1; char ch = buf[ pos - 1 ]; if(ch == ':' && processNamespaces) throw new XmlPullParserException( "when namespaces processing enabled colon can not be at attribute name start", this, null); boolean startsWithXmlns = processNamespaces && ch == 'x'; int xmlnsPos = 0; ch = more(); while(isNameChar(ch)) { if(processNamespaces) { if(startsWithXmlns && xmlnsPos < 5) { ++xmlnsPos; if(xmlnsPos == 1) { if(ch != 'm') startsWithXmlns = false; } else if(xmlnsPos == 2) { if(ch != 'l') startsWithXmlns = false; } else if(xmlnsPos == 3) { if(ch != 'n') startsWithXmlns = false; } else if(xmlnsPos == 4) { if(ch != 's') startsWithXmlns = false; } else if(xmlnsPos == 5) { if(ch != ':') throw new XmlPullParserException( "after xmlns in attribute name must be colon" +"when namespaces are enabled", this, null); //colonPos = pos - 1 + bufAbsoluteStart; } } if(ch == ':') { if(colonPos != -1) throw new XmlPullParserException( "only one colon is allowed in attribute name" +" when namespaces are enabled", this, null); colonPos = pos - 1 + bufAbsoluteStart; } } ch = more(); } ensureAttributesCapacity(attributeCount); // --- start processing attributes String name = null; String prefix = null; // work on prefixes and namespace URI if(processNamespaces) { if(xmlnsPos < 4) startsWithXmlns = false; if(startsWithXmlns) { if(colonPos != -1) { //prefix = attributePrefix[ attributeCount ] = null; final int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); if(nameLen == 0) { throw new XmlPullParserException( "namespace prefix is required after xmlns: " +" when namespaces are enabled", this, null); } name = //attributeName[ attributeCount ] = newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); //pos - 1 - (colonPos + 1 - bufAbsoluteStart) } } else { if(colonPos != -1) { int prefixLen = colonPos - nameStart; prefix = attributePrefix[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart,prefixLen); //colonPos - (nameStart - bufAbsoluteStart)); int nameLen = pos - 2 - (colonPos - bufAbsoluteStart); name = attributeName[ attributeCount ] = newString(buf, colonPos - bufAbsoluteStart + 1, nameLen); //pos - 1 - (colonPos + 1 - bufAbsoluteStart)); //name.substring(0, colonPos-nameStart); } else { prefix = attributePrefix[ attributeCount ] = null; name = attributeName[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart)); } if(!allStringsInterned) { attributeNameHash[ attributeCount ] = name.hashCode(); } } } else { // retrieve name name = attributeName[ attributeCount ] = newString(buf, nameStart - bufAbsoluteStart, pos - 1 - (nameStart - bufAbsoluteStart)); ////assert name != null; if(!allStringsInterned) { attributeNameHash[ attributeCount ] = name.hashCode(); } } // [25] Eq ::= S? '=' S? while(isS(ch)) { ch = more(); } // skip additional spaces if(ch != '=') throw new XmlPullParserException( "expected = after attribute name", this, null); ch = more(); while(isS(ch)) { ch = more(); } // skip additional spaces // [10] AttValue ::= '"' ([^<&"] | Reference)* '"' // | "'" ([^<&'] | Reference)* "'" final char delimit = ch; if(delimit != '"' && delimit != '\'') throw new XmlPullParserException( "attribute value must start with quotation or apostrophe not " +printable(delimit), this, null); // parse until delimit or < and resolve Reference //[67] Reference ::= EntityRef | CharRef //int valueStart = pos + bufAbsoluteStart; boolean normalizedCR = false; usePC = false; pcStart = pcEnd; posStart = pos; while(true) { ch = more(); if(ch == delimit) { break; } if(ch == '<') { throw new XmlPullParserException( "markup not allowed inside attribute value - illegal < ", this, null); } if(ch == '&') { // extractEntityRef posEnd = pos - 1; if(!usePC) { final boolean hadCharData = posEnd > posStart; if(hadCharData) { // posEnd is already set correctly!!! joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; final char[] resolvedEntity = parseEntityRef(); // check if replacement text can be resolved !!! if(resolvedEntity == null) { if(entityRefName == null) { entityRefName = newString(buf, posStart, posEnd - posStart); } throw new XmlPullParserException( "could not resolve entity named '"+printable(entityRefName)+"'", this, null); } // write into PC replacement text - do merge for replacement text!!!! for (int i = 0; i < resolvedEntity.length; i++) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = resolvedEntity[ i ]; } } else if(ch == '\t' || ch == '\n' || ch == '\r') { // do attribute value normalization // as described in http://www.w3.org/TR/REC-xml#AVNormalize // TODO add test for it form spec ... // handle EOL normalization ... if(!usePC) { posEnd = pos - 1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcEnd = pcStart = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); if(ch != '\n' || !normalizedCR) { pc[pcEnd++] = ' '; //'\n'; } } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } } normalizedCR = ch == '\r'; } if(processNamespaces && startsWithXmlns) { String ns = null; if(!usePC) { ns = newStringIntern(buf, posStart, pos - 1 - posStart); } else { ns = newStringIntern(pc, pcStart, pcEnd - pcStart); } ensureNamespacesCapacity(namespaceEnd); int prefixHash = -1; if(colonPos != -1) { if(ns.length() == 0) { throw new XmlPullParserException( "non-default namespace can not be declared to be empty string", this, null); } // declare new namespace namespacePrefix[ namespaceEnd ] = name; if(!allStringsInterned) { prefixHash = namespacePrefixHash[ namespaceEnd ] = name.hashCode(); } } else { // declare new default namespace... namespacePrefix[ namespaceEnd ] = null; //""; //null; //TODO check FIXME Alek if(!allStringsInterned) { prefixHash = namespacePrefixHash[ namespaceEnd ] = -1; } } namespaceUri[ namespaceEnd ] = ns; // detect duplicate namespace declarations!!! final int startNs = elNamespaceCount[ depth - 1 ]; for (int i = namespaceEnd - 1; i >= startNs; --i) { if(((allStringsInterned || name == null) && namespacePrefix[ i ] == name) || (!allStringsInterned && name != null && namespacePrefixHash[ i ] == prefixHash && name.equals(namespacePrefix[ i ]) )) { final String s = name == null ? "default" : "'"+name+"'"; throw new XmlPullParserException( "duplicated namespace declaration for "+s+" prefix", this, null); } } ++namespaceEnd; } else { if(!usePC) { attributeValue[ attributeCount ] = new String(buf, posStart, pos - 1 - posStart); } else { attributeValue[ attributeCount ] = new String(pc, pcStart, pcEnd - pcStart); } ++attributeCount; } posStart = prevPosStart - bufAbsoluteStart; return ch; } protected char[] charRefOneCharBuf = new char[1]; protected char[] parseEntityRef() throws XmlPullParserException, IOException { // entity reference http://www.w3.org/TR/2000/REC-xml-20001006#NT-Reference // [67] Reference ::= EntityRef | CharRef // ASSUMPTION just after & entityRefName = null; posStart = pos; char ch = more(); if(ch == '#') { // parse character reference char charRef = 0; ch = more(); if(ch == 'x') { //encoded in hex while(true) { ch = more(); if(ch >= '0' && ch <= '9') { charRef = (char)(charRef * 16 + (ch - '0')); } else if(ch >= 'a' && ch <= 'f') { charRef = (char)(charRef * 16 + (ch - ('a' - 10))); } else if(ch >= 'A' && ch <= 'F') { charRef = (char)(charRef * 16 + (ch - ('A' - 10))); } else if(ch == ';') { break; } else { throw new XmlPullParserException( "character reference (with hex value) may not contain " +printable(ch), this, null); } } } else { // encoded in decimal while(true) { if(ch >= '0' && ch <= '9') { charRef = (char)(charRef * 10 + (ch - '0')); } else if(ch == ';') { break; } else { throw new XmlPullParserException( "character reference (with decimal value) may not contain " +printable(ch), this, null); } ch = more(); } } posEnd = pos - 1; charRefOneCharBuf[0] = charRef; if(tokenize) { text = newString(charRefOneCharBuf, 0, 1); } return charRefOneCharBuf; } else { // [68] EntityRef ::= '&' Name ';' // scan anem until ; if(!isNameStartChar(ch)) { throw new XmlPullParserException( "entity reference names can not start with character '" +printable(ch)+"'", this, null); } while(true) { ch = more(); if(ch == ';') { break; } if(!isNameChar(ch)) { throw new XmlPullParserException( "entity reference name can not contain character " +printable(ch)+"'", this, null); } } posEnd = pos - 1; // determine what name maps to final int len = posEnd - posStart; if(len == 2 && buf[posStart] == 'l' && buf[posStart+1] == 't') { if(tokenize) { text = "<"; } charRefOneCharBuf[0] = '<'; return charRefOneCharBuf; //if(paramPC || isParserTokenizing) { // if(pcEnd >= pc.length) ensurePC(); // pc[pcEnd++] = '<'; //} } else if(len == 3 && buf[posStart] == 'a' && buf[posStart+1] == 'm' && buf[posStart+2] == 'p') { if(tokenize) { text = "&"; } charRefOneCharBuf[0] = '&'; return charRefOneCharBuf; } else if(len == 2 && buf[posStart] == 'g' && buf[posStart+1] == 't') { if(tokenize) { text = ">"; } charRefOneCharBuf[0] = '>'; return charRefOneCharBuf; } else if(len == 4 && buf[posStart] == 'a' && buf[posStart+1] == 'p' && buf[posStart+2] == 'o' && buf[posStart+3] == 's') { if(tokenize) { text = "'"; } charRefOneCharBuf[0] = '\''; return charRefOneCharBuf; } else if(len == 4 && buf[posStart] == 'q' && buf[posStart+1] == 'u' && buf[posStart+2] == 'o' && buf[posStart+3] == 't') { if(tokenize) { text = "\""; } charRefOneCharBuf[0] = '"'; return charRefOneCharBuf; } else { final char[] result = lookuEntityReplacement(len); if(result != null) { return result; } } if(tokenize) text = null; return null; } } protected char[] lookuEntityReplacement(int entitNameLen) throws XmlPullParserException, IOException { if(!allStringsInterned) { final int hash = fastHash(buf, posStart, posEnd - posStart); LOOP: for (int i = entityEnd - 1; i >= 0; --i) { if(hash == entityNameHash[ i ] && entitNameLen == entityNameBuf[ i ].length) { final char[] entityBuf = entityNameBuf[ i ]; for (int j = 0; j < entitNameLen; j++) { if(buf[posStart + j] != entityBuf[j]) continue LOOP; } if(tokenize) text = entityReplacement[ i ]; return entityReplacementBuf[ i ]; } } } else { entityRefName = newString(buf, posStart, posEnd - posStart); for (int i = entityEnd - 1; i >= 0; --i) { // take advantage that interning for newStirng is enforced if(entityRefName == entityName[ i ]) { if(tokenize) text = entityReplacement[ i ]; return entityReplacementBuf[ i ]; } } } return null; } protected void parseComment() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.5 Comments //ASSUMPTION: seen ch = more(); if(seenDashDash && ch != '>') { throw new XmlPullParserException( "in comment after two dashes (--) next character must be >" +" not "+printable(ch), this, null); } if(ch == '-') { if(!seenDash) { seenDash = true; } else { seenDashDash = true; seenDash = false; } } else if(ch == '>') { if(seenDashDash) { break; // found end sequence!!!! } else { seenDashDash = false; } seenDash = false; } else { seenDash = false; } if(normalizeIgnorableWS) { if(ch == '\r') { normalizedCR = true; //posEnd = pos -1; //joinPC(); // posEnd is alreadys set if(!usePC) { posEnd = pos -1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "comment started on line "+curLine+" and column "+curColumn+" was not closed", this, ex); } if(tokenize) { posEnd = pos - 3; if(usePC) { pcEnd -= 2; } } } protected boolean parsePI() throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.6 Processing Instructions // [16] PI ::= '' Char*)))? '?>' // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) //ASSUMPTION: seen //ch = more(); if(ch == '?') { seenQ = true; } else if(ch == '>') { if(seenQ) { break; // found end sequence!!!! } seenQ = false; } else { if(piTargetEnd == -1 && isS(ch)) { piTargetEnd = pos - 1 + bufAbsoluteStart; // [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) if((piTargetEnd - piTargetStart) == 3) { if((buf[piTargetStart] == 'x' || buf[piTargetStart] == 'X') && (buf[piTargetStart+1] == 'm' || buf[piTargetStart+1] == 'M') && (buf[piTargetStart+2] == 'l' || buf[piTargetStart+2] == 'L') ) { if(piTargetStart > 3) { // posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } ch = more(); } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "processing instruction started on line "+curLine+" and column "+curColumn +" was not closed", this, ex); } if(piTargetEnd == -1) { piTargetEnd = pos - 2 + bufAbsoluteStart; //throw new XmlPullParserException( // "processing instruction must have PITarget name", this, null); } piTargetStart -= bufAbsoluteStart; piTargetEnd -= bufAbsoluteStart; if(tokenize) { posEnd = pos - 2; if(normalizeIgnorableWS) { --pcEnd; } } return true; } // protected final static char[] VERSION = {'v','e','r','s','i','o','n'}; // protected final static char[] NCODING = {'n','c','o','d','i','n','g'}; // protected final static char[] TANDALONE = {'t','a','n','d','a','l','o','n','e'}; // protected final static char[] YES = {'y','e','s'}; // protected final static char[] NO = {'n','o'}; protected final static char[] VERSION = "version".toCharArray(); protected final static char[] NCODING = "ncoding".toCharArray(); protected final static char[] TANDALONE = "tandalone".toCharArray(); protected final static char[] YES = "yes".toCharArray(); protected final static char[] NO = "no".toCharArray(); protected void parseXmlDecl(char ch) throws XmlPullParserException, IOException { // [23] XMLDecl ::= '' // first make sure that relative positions will stay OK preventBufferCompaction = true; bufStart = 0; // necessary to keep pos unchanged during expansion! // --- parse VersionInfo // [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') // parse is positioned just on first S past 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && ch != '_' && ch != '.' && ch != ':' && ch != '-') { throw new XmlPullParserException( " 'z') && (ch < 'A' || ch > 'Z')) { throw new XmlPullParserException( " 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') && ch != '.' && ch != '_' && ch != '-') { throw new XmlPullParserException( " as last part of ') { throw new XmlPullParserException( "expected ?> as last part of ' int bracketLevel = 0; final boolean normalizeIgnorableWS = tokenize == true && roundtripSupported == false; boolean normalizedCR = false; while(true) { ch = more(); if(ch == '[') ++bracketLevel; if(ch == ']') --bracketLevel; if(ch == '>' && bracketLevel == 0) break; if(normalizeIgnorableWS) { if(ch == '\r') { normalizedCR = true; //posEnd = pos -1; //joinPC(); // posEnd is alreadys set if(!usePC) { posEnd = pos -1; if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } posEnd = pos - 1; } protected void parseCDSect(boolean hadCharData) throws XmlPullParserException, IOException { // implements XML 1.0 Section 2.7 CDATA Sections // [18] CDSect ::= CDStart CData CDEnd // [19] CDStart ::= '' Char*)) // [21] CDEnd ::= ']]>' //ASSUMPTION: seen posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } } } boolean seenBracket = false; boolean seenBracketBracket = false; boolean normalizedCR = false; while(true) { // scan until it hits "]]>" ch = more(); if(ch == ']') { if(!seenBracket) { seenBracket = true; } else { seenBracketBracket = true; //seenBracket = false; } } else if(ch == '>') { if(seenBracket && seenBracketBracket) { break; // found end sequence!!!! } else { seenBracketBracket = false; } seenBracket = false; } else { if(seenBracket) { seenBracket = false; } } if(normalizeInput) { // deal with normalization issues ... if(ch == '\r') { normalizedCR = true; posStart = cdStart - bufAbsoluteStart; posEnd = pos - 1; // posEnd is alreadys set if(!usePC) { if(posEnd > posStart) { joinPC(); } else { usePC = true; pcStart = pcEnd = 0; } } //assert usePC == true; if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } else if(ch == '\n') { if(!normalizedCR && usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = '\n'; } normalizedCR = false; } else { if(usePC) { if(pcEnd >= pc.length) ensurePC(pcEnd); pc[pcEnd++] = ch; } normalizedCR = false; } } } } catch(EOFException ex) { // detect EOF and create meaningful error ... throw new XmlPullParserException( "CDATA section started on line "+curLine+" and column "+curColumn+" was not closed", this, ex); } if(normalizeInput) { if(usePC) { pcEnd = pcEnd - 2; } } posStart = cdStart - bufAbsoluteStart; posEnd = pos - 3; } protected void fillBuf() throws IOException, XmlPullParserException { if(reader == null) throw new XmlPullParserException( "reader must be set before parsing is started"); // see if we are in compaction area if(bufEnd > bufSoftLimit) { // expand buffer it makes sense!!!! boolean compact = bufStart > bufSoftLimit; boolean expand = false; if(preventBufferCompaction) { compact = false; expand = true; } else if(!compact) { //freeSpace if(bufStart < buf.length / 2) { // less then half buffer available forcompactin --> expand instead!!! expand = true; } else { // at least half of buffer can be reclaimed --> worthwhile effort!!! compact = true; } } // if buffer almost full then compact it if(compact) { //TODO: look on trashing // //assert bufStart > 0 System.arraycopy(buf, bufStart, buf, 0, bufEnd - bufStart); if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() compacting "+bufStart +" bufEnd="+bufEnd +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd +" buf first 100 chars:"+new String(buf, bufStart, bufEnd - bufStart < 100 ? bufEnd - bufStart : 100 )); } else if(expand) { final int newSize = 2 * buf.length; final char newBuf[] = new char[ newSize ]; if(TRACE_SIZING) System.out.println("TRACE_SIZING fillBuf() "+buf.length+" => "+newSize); System.arraycopy(buf, bufStart, newBuf, 0, bufEnd - bufStart); buf = newBuf; if(bufLoadFactor > 0) { bufSoftLimit = ( bufLoadFactor * buf.length ) /100; } } else { throw new XmlPullParserException("internal error in fillBuffer()"); } bufEnd -= bufStart; pos -= bufStart; posStart -= bufStart; posEnd -= bufStart; bufAbsoluteStart += bufStart; bufStart = 0; if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() after bufEnd="+bufEnd +" pos="+pos+" posStart="+posStart+" posEnd="+posEnd +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); } // at least one charcter must be read or error final int len = buf.length - bufEnd > READ_CHUNK_SIZE ? READ_CHUNK_SIZE : buf.length - bufEnd; final int ret = reader.read(buf, bufEnd, len); if(ret > 0) { bufEnd += ret; if(TRACE_SIZING) System.out.println( "TRACE_SIZING fillBuf() after filling in buffer" +" buf first 100 chars:"+new String(buf, 0, bufEnd < 100 ? bufEnd : 100)); return; } if(ret == -1) { if(bufAbsoluteStart == 0 && pos == 0) { throw new EOFException("input contained no data"); } else { if(seenRoot && depth == 0) { // inside parsing epilog!!! reachedEnd = true; return; } else { StringBuffer expectedTagStack = new StringBuffer(); if(depth > 0) { //final char[] cbuf = elRawName[depth]; //final String startname = new String(cbuf, 0, elRawNameEnd[depth]); expectedTagStack.append(" - expected end tag"); if(depth > 1) { expectedTagStack.append("s"); //more than one end tag } expectedTagStack.append(" "); for (int i = depth; i > 0; i--) { String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); expectedTagStack.append("'); } expectedTagStack.append(" to close"); for (int i = depth; i > 0; i--) { if(i != depth) { expectedTagStack.append(" and"); //more than one end tag } String tagName = new String(elRawName[i], 0, elRawNameEnd[i]); expectedTagStack.append(" start tag <"+tagName+">"); expectedTagStack.append(" from line "+elRawNameLine[i]); } expectedTagStack.append(", parser stopped on"); } throw new EOFException("no more data available" +expectedTagStack.toString()+getPositionDescription()); } } } else { throw new IOException("error reading input, returned "+ret); } } protected char more() throws IOException, XmlPullParserException { if(pos >= bufEnd) { fillBuf(); // this return value should be ignonored as it is used in epilog parsing ... if(reachedEnd) return (char)-1; } final char ch = buf[pos++]; //line/columnNumber if(ch == '\n') { ++lineNumber; columnNumber = 1; } else { ++columnNumber; } //System.out.print(ch); return ch; } // /** // * This function returns position of parser in XML input stream // * (how many characters were processed. // *

NOTE: this logical position and not byte offset as encodings // * such as UTF8 may use more than one byte to encode one character. // */ // public int getCurrentInputPosition() { // return pos + bufAbsoluteStart; // } protected void ensurePC(int end) { //assert end >= pc.length; final int newSize = end > READ_CHUNK_SIZE ? 2 * end : 2 * READ_CHUNK_SIZE; final char[] newPC = new char[ newSize ]; if(TRACE_SIZING) System.out.println("TRACE_SIZING ensurePC() "+pc.length+" ==> "+newSize+" end="+end); System.arraycopy(pc, 0, newPC, 0, pcEnd); pc = newPC; //assert end < pc.length; } protected void joinPC() { //assert usePC == false; //assert posEnd > posStart; final int len = posEnd - posStart; final int newEnd = pcEnd + len + 1; if(newEnd >= pc.length) ensurePC(newEnd); // add 1 for extra space for one char //assert newEnd < pc.length; System.arraycopy(buf, posStart, pc, pcEnd, len); pcEnd += len; usePC = true; } protected char requireInput(char ch, char[] input) throws XmlPullParserException, IOException { for (int i = 0; i < input.length; i++) { if(ch != input[i]) { throw new XmlPullParserException( "expected "+printable(input[i])+" in "+new String(input) +" and not "+printable(ch), this, null); } ch = more(); } return ch; } protected char requireNextS() throws XmlPullParserException, IOException { final char ch = more(); if(!isS(ch)) { throw new XmlPullParserException( "white space is required and not "+printable(ch), this, null); } return skipS(ch); } protected char skipS(char ch) throws XmlPullParserException, IOException { while(isS(ch)) { ch = more(); } // skip additional spaces return ch; } // nameStart / name lookup tables based on XML 1.1 http://www.w3.org/TR/2001/WD-xml11-20011213/ protected static final int LOOKUP_MAX = 0x400; protected static final char LOOKUP_MAX_CHAR = (char)LOOKUP_MAX; // protected static int lookupNameStartChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; // protected static int lookupNameChar[] = new int[ LOOKUP_MAX_CHAR / 32 ]; protected static boolean lookupNameStartChar[] = new boolean[ LOOKUP_MAX ]; protected static boolean lookupNameChar[] = new boolean[ LOOKUP_MAX ]; private static final void setName(char ch) //{ lookupNameChar[ (int)ch / 32 ] |= (1 << (ch % 32)); } { lookupNameChar[ ch ] = true; } private static final void setNameStart(char ch) //{ lookupNameStartChar[ (int)ch / 32 ] |= (1 << (ch % 32)); setName(ch); } { lookupNameStartChar[ ch ] = true; setName(ch); } static { setNameStart(':'); for (char ch = 'A'; ch <= 'Z'; ++ch) setNameStart(ch); setNameStart('_'); for (char ch = 'a'; ch <= 'z'; ++ch) setNameStart(ch); for (char ch = '\u00c0'; ch <= '\u02FF'; ++ch) setNameStart(ch); for (char ch = '\u0370'; ch <= '\u037d'; ++ch) setNameStart(ch); for (char ch = '\u037f'; ch < '\u0400'; ++ch) setNameStart(ch); setName('-'); setName('.'); for (char ch = '0'; ch <= '9'; ++ch) setName(ch); setName('\u00b7'); for (char ch = '\u0300'; ch <= '\u036f'; ++ch) setName(ch); } //private final static boolean isNameStartChar(char ch) { protected boolean isNameStartChar(char ch) { return (ch < LOOKUP_MAX_CHAR && lookupNameStartChar[ ch ]) || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF') ; // if(ch < LOOKUP_MAX_CHAR) return lookupNameStartChar[ ch ]; // else return ch <= '\u2027' // || (ch >= '\u202A' && ch <= '\u218F') // || (ch >= '\u2800' && ch <= '\uFFEF') // ; //return false; // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' // || (ch >= '0' && ch <= '9'); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; // if(ch <= '\u2027') return true; // //[#x202A-#x218F] // if(ch < '\u202A') return false; // if(ch <= '\u218F') return true; // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] // if(ch < '\u2800') return false; // if(ch <= '\uFFEF') return true; // return false; // else return (supportXml11 && ( (ch < '\u2027') || (ch > '\u2029' && ch < '\u2200') ... } //private final static boolean isNameChar(char ch) { protected boolean isNameChar(char ch) { //return isNameStartChar(ch); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; return (ch < LOOKUP_MAX_CHAR && lookupNameChar[ ch ]) || (ch >= LOOKUP_MAX_CHAR && ch <= '\u2027') || (ch >= '\u202A' && ch <= '\u218F') || (ch >= '\u2800' && ch <= '\uFFEF') ; //return false; // return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == ':' // || (ch >= '0' && ch <= '9'); // if(ch < LOOKUP_MAX_CHAR) return (lookupNameStartChar[ (int)ch / 32 ] & (1 << (ch % 32))) != 0; //else return // else if(ch <= '\u2027') return true; // //[#x202A-#x218F] // else if(ch < '\u202A') return false; // else if(ch <= '\u218F') return true; // // added pairts [#x2800-#xD7FF] | [#xE000-#xFDCF] | [#xFDE0-#xFFEF] | [#x10000-#x10FFFF] // else if(ch < '\u2800') return false; // else if(ch <= '\uFFEF') return true; //else return false; } protected boolean isS(char ch) { return (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'); // || (supportXml11 && (ch == '\u0085' || ch == '\u2028'); } //protected boolean isChar(char ch) { return (ch < '\uD800' || ch > '\uDFFF') // ch != '\u0000' ch < '\uFFFE' //protected char printable(char ch) { return ch; } protected String printable(char ch) { if(ch == '\n') { return "\\n"; } else if(ch == '\r') { return "\\r"; } else if(ch == '\t') { return "\\t"; } else if(ch == '\'') { return "\\'"; } if(ch > 127 || ch < 32) { return "\\u"+Integer.toHexString((int)ch); } return ""+ch; } protected String printable(String s) { if(s == null) return null; final int sLen = s.length(); StringBuffer buf = new StringBuffer(sLen + 10); for(int i = 0; i < sLen; ++i) { buf.append(printable(s.charAt(i))); } s = buf.toString(); return s; } } /* * Indiana University Extreme! Lab Software License, Version 1.2 * * Copyright (C) 2003 The Trustees of Indiana University. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * 1) All redistributions of source code must retain the above * copyright notice, the list of authors in the original source * code, this list of conditions and the disclaimer listed in this * license; * * 2) All redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the disclaimer * listed in this license in the documentation and/or other * materials provided with the distribution; * * 3) Any documentation included with all redistributions must include * the following acknowledgement: * * "This product includes software developed by the Indiana * University Extreme! Lab. For further information please visit * http://www.extreme.indiana.edu/" * * Alternatively, this acknowledgment may appear in the software * itself, and wherever such third-party acknowledgments normally * appear. * * 4) The name "Indiana University" or "Indiana University * Extreme! Lab" shall not be used to endorse or promote * products derived from this software without prior written * permission from Indiana University. For written permission, * please contact http://www.extreme.indiana.edu/. * * 5) Products derived from this software may not use "Indiana * University" name nor may "Indiana University" appear in their name, * without prior written permission of the Indiana University. * * Indiana University provides no reassurances that the source code * provided does not infringe the patent or any other intellectual * property rights of any other entity. Indiana University disclaims any * liability to any recipient for claims brought by any other entity * based on infringement of intellectual property rights or otherwise. * * LICENSEE UNDERSTANDS THAT SOFTWARE IS PROVIDED "AS IS" FOR WHICH * NO WARRANTIES AS TO CAPABILITIES OR ACCURACY ARE MADE. INDIANA * UNIVERSITY GIVES NO WARRANTIES AND MAKES NO REPRESENTATION THAT * SOFTWARE IS FREE OF INFRINGEMENT OF THIRD PARTY PATENT, COPYRIGHT, OR * OTHER PROPRIETARY RIGHTS. INDIANA UNIVERSITY MAKES NO WARRANTIES THAT * SOFTWARE IS FREE FROM "BUGS", "VIRUSES", "TROJAN HORSES", "TRAP * DOORS", "WORMS", OR OTHER HARMFUL CODE. LICENSEE ASSUMES THE ENTIRE * RISK AS TO THE PERFORMANCE OF SOFTWARE AND/OR ASSOCIATED MATERIALS, * AND TO THE PERFORMANCE AND VALIDITY OF INFORMATION GENERATED USING * SOFTWARE. */ ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/AbstractMerger.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/AbstractMer0000644000175000017500000000714411202560777033412 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.List; import org.codehaus.plexus.util.IOUtil; import org.jdom.Document; import org.jdom.JDOMException; import org.jdom.input.SAXBuilder; import org.jdom.output.XMLOutputter; /** * Base class for common mergers. * * @author Brett Porter */ public abstract class AbstractMerger implements Merger { /** * @see org.codehaus.plexus.metadata.merge.Merger#writeMergedDocument(org.jdom.Document, * java.io.File) */ public void writeMergedDocument( Document mergedDocument, File file ) throws IOException { if ( !file.getParentFile().exists() ) { file.getParentFile().mkdirs(); } XMLOutputter out = new XMLOutputter(); Writer fw = null; try { fw = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" ); out.output( mergedDocument, fw ); } finally { IOUtil.close( fw ); } } public void mergeDescriptors( File outputDescriptor, List descriptors ) throws IOException { SAXBuilder builder = new SAXBuilder( Driver.class.getName() ); Document finalDoc = null; for ( File f : descriptors ) { try { Document doc = builder.build( f ); if ( finalDoc != null ) { // Last specified has dominance finalDoc = merge( doc, finalDoc ); } else { finalDoc = doc; } } catch ( JDOMException e ) { throw new IOException( "Invalid input descriptor for merge: " + f + " --> " + e.getMessage() ); } catch ( MergeException e ) { throw new IOException( "Error merging descriptor: " + f + " --> " + e.getMessage() ); } } if ( finalDoc != null ) { try { writeMergedDocument( finalDoc, outputDescriptor ); } catch ( IOException e ) { throw new IOException( "Error writing merged descriptor: " + outputDescriptor ); } } } } ././@LongLink0000000000000000000000000000015500000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MergeException.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/MergeExcept0000644000175000017500000000305711054033060033373 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Rahul Thakur * @version $Id: MergeException.java 7689 2008-08-23 16:09:20Z jvanzyl $ */ public class MergeException extends Exception { public MergeException( String message, Throwable cause ) { super( message, cause ); } public MergeException( String message ) { super( message ); } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/Merger.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/Merger.java0000644000175000017500000000455011112213150033316 0ustar twernertwernerpackage org.codehaus.plexus.metadata.merge; /* * The MIT License * * Copyright (c) 2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ import java.io.File; import java.io.IOException; import java.util.List; import org.jdom.Document; /** * @author Rahul Thakur * @version $Id: Merger.java 7868 2008-11-23 08:38:00Z jvanzyl $ */ public interface Merger { String ROLE = Merger.class.getName(); /** * Merge with the recessive document. * * @param dDocument the dominant document. * @param rDocument the recessive document. * @return the merged {@link Document} instance. * * @throws MergeException if there was an error in merge. */ Document merge( Document dDocument, Document rDocument ) throws MergeException; /** * Allows writing out a merged JDom Document to the specified file. * * @param mergedDocument the merged {@link Document} instance. * @param file File to write the merged contents to. * @throws IOException if there was an error while writing merged contents to the specified file. */ void writeMergedDocument( Document mergedDocument, File file ) throws IOException; void mergeDescriptors( File outputDescriptor, List descriptors ) throws IOException; } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/Driver.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/merge/Driver.java0000644000175000017500000004310211202040413033324 0ustar twernertwerner/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- //------100-columns-wide------>|*/ // for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/) package org.codehaus.plexus.metadata.merge; import java.io.InputStream; import java.io.IOException; import java.io.Reader; // not J2ME classes -- remove if you want to run in MIDP devices import java.net.URL; import java.net.MalformedURLException; // not J2ME classes import java.io.FileInputStream; import java.io.FileNotFoundException; import org.codehaus.plexus.util.xml.pull.XmlPullParser; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; import org.xml.sax.Attributes; import org.xml.sax.DTDHandler; import org.xml.sax.ContentHandler; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; /** * SAX2 Driver that pulls events from XmlPullParser * and comverts them into SAX2 callbacks. * * @author Aleksander Slominski */ public class Driver implements Locator, XMLReader, Attributes { protected static final String DECLARATION_HANDLER_PROPERTY = "http://xml.org/sax/properties/declaration-handler"; protected static final String LEXICAL_HANDLER_PROPERTY = "http://xml.org/sax/properties/lexical-handler"; protected static final String NAMESPACES_FEATURE = "http://xml.org/sax/features/namespaces"; protected static final String NAMESPACE_PREFIXES_FEATURE = "http://xml.org/sax/features/namespace-prefixes"; protected static final String VALIDATION_FEATURE = "http://xml.org/sax/features/validation"; protected static final String APACHE_SCHEMA_VALIDATION_FEATURE = "http://apache.org/xml/features/validation/schema"; protected static final String APACHE_DYNAMIC_VALIDATION_FEATURE = "http://apache.org/xml/features/validation/dynamic"; protected ContentHandler contentHandler = new DefaultHandler(); protected ErrorHandler errorHandler = new DefaultHandler();; protected String systemId; protected XmlPullParser pp; public Driver() throws XmlPullParserException { pp = new MXParser(); try { setFeature( NAMESPACES_FEATURE, true ); setFeature( NAMESPACE_PREFIXES_FEATURE, true ); } catch ( Exception e ) { e.printStackTrace(); } } // -- Attributes interface public int getLength() { return pp.getAttributeCount(); } public String getURI(int index) { return pp.getAttributeNamespace(index); } public String getLocalName(int index) { return pp.getAttributeName(index); } public String getQName(int index) { final String prefix = pp.getAttributePrefix(index); if(prefix != null) { return prefix+':'+pp.getAttributeName(index); } else { return pp.getAttributeName(index); } } public String getType(int index) { return pp.getAttributeType(index); } public String getValue(int index) { return pp.getAttributeValue(index); } public int getIndex(String uri, String localName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeNamespace(i).equals(uri) && pp.getAttributeName(i).equals(localName)) { return i; } } return -1; } public int getIndex(String qName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeName(i).equals(qName)) { return i; } } return -1; } public String getType(String uri, String localName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeNamespace(i).equals(uri) && pp.getAttributeName(i).equals(localName)) { return pp.getAttributeType(i); } } return null; } public String getType(String qName) { for (int i = 0; i < pp.getAttributeCount(); i++) { if(pp.getAttributeName(i).equals(qName)) { return pp.getAttributeType(i); } } return null; } public String getValue(String uri, String localName) { return pp.getAttributeValue(uri, localName); } public String getValue(String qName) { return pp.getAttributeValue(null, qName); } // -- Locator interface public String getPublicId() { return null; } public String getSystemId() { return systemId; } public int getLineNumber() { return pp.getLineNumber(); } public int getColumnNumber() { return pp.getColumnNumber(); } // --- XMLReader interface //"http://xml.org/sax/features/namespaces", //true public boolean getFeature(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if(NAMESPACES_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES); } else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES); } else if(VALIDATION_FEATURE.equals(name)) { return pp.getFeature(XmlPullParser.FEATURE_VALIDATION); // } else if(APACHE_SCHEMA_VALIDATION_FEATURE.equals(name)) { // return false; //TODO // } else if(APACHE_DYNAMIC_VALIDATION_FEATURE.equals(name)) { // return false; //TODO } else { return pp.getFeature(name); //throw new SAXNotRecognizedException("unrecognized feature "+name); } } public void setFeature (String name, boolean value) throws SAXNotRecognizedException, SAXNotSupportedException { try { if(NAMESPACES_FEATURE.equals(name)) { pp.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, value); } else if(NAMESPACE_PREFIXES_FEATURE.equals(name)) { if(pp.getFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES) != value) { pp.setFeature(XmlPullParser.FEATURE_REPORT_NAMESPACE_ATTRIBUTES, value); } } else if(VALIDATION_FEATURE.equals(name)) { pp.setFeature(XmlPullParser.FEATURE_VALIDATION, value); } else { pp.setFeature(name, value); //throw new SAXNotRecognizedException("unrecognized feature "+name); } } catch(XmlPullParserException ex) { throw new SAXNotSupportedException("problem with setting feature "+name+": "+ex); } } public Object getProperty (String name) throws SAXNotRecognizedException, SAXNotSupportedException { if(DECLARATION_HANDLER_PROPERTY.equals(name)) { return null; } else if(LEXICAL_HANDLER_PROPERTY.equals(name)) { return null; } else { return pp.getProperty(name); //throw new SAXNotRecognizedException("not recognized get property "+name); } } public void setProperty (String name, Object value) throws SAXNotRecognizedException, SAXNotSupportedException { // if(DECLARATION_HANDLER_PROPERTY.equals(name)) { throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value); } else if(LEXICAL_HANDLER_PROPERTY.equals(name)) { throw new SAXNotSupportedException("not supported setting property "+name);//+" to "+value); } else { try { pp.setProperty(name, value); } catch(XmlPullParserException ex) { throw new SAXNotSupportedException("not supported set property "+name+": "+ ex); } //throw new SAXNotRecognizedException("not recognized set property "+name); } } public void setEntityResolver (EntityResolver resolver) {} public EntityResolver getEntityResolver () { return null; } public void setDTDHandler (DTDHandler handler) {} public DTDHandler getDTDHandler () { return null; } public void setContentHandler (ContentHandler handler) { this.contentHandler = handler; } public ContentHandler getContentHandler() { return contentHandler; } public void setErrorHandler(ErrorHandler handler) { this.errorHandler = handler; } public ErrorHandler getErrorHandler() { return errorHandler; } public void parse(InputSource source) throws SAXException, IOException { systemId = source.getSystemId(); contentHandler.setDocumentLocator(this); final Reader reader = source.getCharacterStream(); try { if (reader == null) { InputStream stream = source.getByteStream(); final String encoding = source.getEncoding(); if (stream == null) { systemId = source.getSystemId(); if(systemId == null) { SAXParseException saxException = new SAXParseException( "null source systemId" , this); errorHandler.fatalError(saxException); return; } // NOTE: replace with Connection to run in J2ME environment try { final URL url = new URL(systemId); stream = url.openStream(); } catch (MalformedURLException nue) { try { stream = new FileInputStream(systemId); } catch (FileNotFoundException fnfe) { final SAXParseException saxException = new SAXParseException( "could not open file with systemId "+systemId, this, fnfe); errorHandler.fatalError(saxException); return; } } } pp.setInput(stream, encoding); } else { pp.setInput(reader); } } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex); //if(DEBUG) ex.printStackTrace(); errorHandler.fatalError(saxException); return; } // start parsing - move to first start tag try { contentHandler.startDocument(); // get first event pp.next(); // it should be start tag... if(pp.getEventType() != XmlPullParser.START_TAG) { final SAXParseException saxException = new SAXParseException( "expected start tag not"+pp.getPositionDescription(), this); //throw saxException; errorHandler.fatalError(saxException); return; } } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException( "parsing initialization error: "+ex, this, ex); //ex.printStackTrace(); errorHandler.fatalError(saxException); return; } // now real parsing can start! parseSubTree(pp); // and finished ... contentHandler.endDocument(); } public void parse(String systemId) throws SAXException, IOException { parse(new InputSource(systemId)); } public void parseSubTree(XmlPullParser pp) throws SAXException, IOException { this.pp = pp; final boolean namespaceAware = pp.getFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES); try { if(pp.getEventType() != XmlPullParser.START_TAG) { throw new SAXException( "start tag must be read before skiping subtree"+pp.getPositionDescription()); } final int[] holderForStartAndLength = new int[2]; final StringBuffer rawName = new StringBuffer(16); String prefix = null; String name = null; int level = pp.getDepth() - 1; int type = XmlPullParser.START_TAG; LOOP: do { switch(type) { case XmlPullParser.START_TAG: if(namespaceAware) { final int depth = pp.getDepth() - 1; final int countPrev = (level > depth) ? pp.getNamespaceCount(depth) : 0; //int countPrev = pp.getNamespaceCount(pp.getDepth() - 1); final int count = pp.getNamespaceCount(depth + 1); for (int i = countPrev; i < count; i++) { contentHandler.startPrefixMapping( pp.getNamespacePrefix(i), pp.getNamespaceUri(i) ); } name = pp.getName(); prefix = pp.getPrefix(); if(prefix != null) { rawName.setLength(0); rawName.append(prefix); rawName.append(':'); rawName.append(name); } startElement(pp.getNamespace(), name, prefix != null ? name : rawName.toString()); } else { startElement(pp.getNamespace(), pp.getName(), pp.getName()); } //++level; break; case XmlPullParser.TEXT: final char[] chars = pp.getTextCharacters(holderForStartAndLength); contentHandler.characters(chars, holderForStartAndLength[0], //start holderForStartAndLength[1] //len ); break; case XmlPullParser.END_TAG: //--level; if(namespaceAware) { name = pp.getName(); prefix = pp.getPrefix(); if(prefix != null) { rawName.setLength(0); rawName.append(prefix); rawName.append(':'); rawName.append(name); } contentHandler.endElement(pp.getNamespace(), name, prefix != null ? name : rawName.toString() ); // when entering show prefixes for all levels!!!! final int depth = pp.getDepth(); final int countPrev = (level > depth) ? pp.getNamespaceCount(pp.getDepth()) : 0; int count = pp.getNamespaceCount(pp.getDepth() - 1); // undeclare them in reverse order for (int i = count - 1; i >= countPrev; i--) { contentHandler.endPrefixMapping( pp.getNamespacePrefix(i) ); } } else { contentHandler.endElement(pp.getNamespace(), pp.getName(), pp.getName() ); } break; case XmlPullParser.END_DOCUMENT: break LOOP; } type = pp.next(); } while(pp.getDepth() > level); } catch (XmlPullParserException ex) { final SAXParseException saxException = new SAXParseException("parsing error: "+ex, this, ex); ex.printStackTrace(); errorHandler.fatalError(saxException); } } /** * Calls {@link ContentHandler.startElement(String, String, String, Attributes) startElement} * on the ContentHandler with this driver object as the * {@link Attributes} implementation. In default implementation * {@link Attributes} object is valid only during this method call and may not * be stored. Sub-classes can overwrite this method to cache attributes. */ protected void startElement(String namespace, String localName, String qName) throws SAXException { contentHandler.startElement(namespace, localName, qName, this); } } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ClassComponentDescriptorExtractor.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ClassComponentDes0000644000175000017500000001222311202040413033436 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner; import org.codehaus.plexus.metadata.gleaner.ClassComponentGleaner; import org.codehaus.plexus.util.DirectoryScanner; /** * Extracts {@link ComponentDescriptor} from class files. * * @version $Id: ClassComponentDescriptorExtractor.java 8174 2009-05-11 15:15:23Z jvanzyl $ */ public class ClassComponentDescriptorExtractor extends ComponentDescriptorExtractorSupport { private ClassComponentGleaner gleaner; public ClassComponentDescriptorExtractor( final ClassComponentGleaner gleaner ) { this.gleaner = gleaner; } public ClassComponentDescriptorExtractor() { this.gleaner = new AnnotationComponentGleaner(); } public List> extract( MetadataGenerationRequest configuration, final ComponentDescriptor[] roleDefaults ) throws Exception { // We don't have a reasonable default to use, so just puke up if ( gleaner == null ) { throw new IllegalStateException( "Gleaner is not bound" ); } if ( !configuration.classesDirectory.exists() ) { return Collections.emptyList(); } if ( configuration.useContextClassLoader ) { return extract( configuration.classesDirectory, Thread.currentThread().getContextClassLoader(), getDefaultsByRole( roleDefaults ) ); } else { ClassLoader prev = Thread.currentThread().getContextClassLoader(); ClassLoader cl = createClassLoader( configuration.classpath ); Thread.currentThread().setContextClassLoader( cl ); try { return extract( configuration.classesDirectory, cl, getDefaultsByRole( roleDefaults ) ); } finally { Thread.currentThread().setContextClassLoader( prev ); } } } private ClassLoader createClassLoader( final List elements ) throws Exception { List list = new ArrayList(); // Add the projects dependencies for ( String filename : elements ) { try { list.add( new File( filename ).toURI().toURL() ); } catch ( MalformedURLException e ) { throw new MojoExecutionException( "Invalid classpath entry: " + filename, e ); } } URL[] urls = list.toArray( new URL[list.size()] ); //getLogger().debug( "Classpath:" ); for ( int i = 0; i < urls.length; i++ ) { //getLogger().debug( " " + urls[i] ); } return new URLClassLoader( urls, null ); } private List> extract( File classesDir, ClassLoader cl, Map> defaultsByRole ) throws Exception { assert classesDir != null; assert cl != null; assert defaultsByRole != null; List> descriptors = new ArrayList>(); DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir( classesDir ); scanner.addDefaultExcludes(); scanner.setIncludes( new String[] { "**/*.class" } ); //getLogger().debug( "Scanning for classes in: " + classesDir ); scanner.scan(); String[] includes = scanner.getIncludedFiles(); for ( String include : includes ) { String className = include.substring( 0, include.lastIndexOf( ".class" ) ).replace( '\\', '.' ).replace( '/', '.' ); try { // Class type = cl.loadClass( className ); ComponentDescriptor descriptor = gleaner.glean( className, cl ); if ( descriptor != null ) { applyDefaults( descriptor, defaultsByRole ); descriptors.add( descriptor ); } } catch ( VerifyError e ) { // getLogger().error( "Failed to load class: " + className + "; cause: " + e ); } } return descriptors; } }././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/SourceComponentDescriptorExtractor.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/SourceComponentDe0000644000175000017500000000623611202040413033455 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.metadata.gleaner.QDoxComponentGleaner; import org.codehaus.plexus.metadata.gleaner.SourceComponentGleaner; import org.codehaus.plexus.util.StringUtils; import com.thoughtworks.qdox.JavaDocBuilder; import com.thoughtworks.qdox.model.JavaClass; /** * Extracts {@link ComponentDescriptor} from source files. * * @version $Rev: 8174 $ $Date: 2009-05-11 17:15:23 +0200 (Mo, 11. Mai 2009) $ */ public class SourceComponentDescriptorExtractor extends ComponentDescriptorExtractorSupport { private SourceComponentGleaner gleaner; public SourceComponentDescriptorExtractor() { } public SourceComponentDescriptorExtractor( final SourceComponentGleaner gleaner ) { this.gleaner = gleaner; } public List> extract( MetadataGenerationRequest configuration, final ComponentDescriptor[] roleDefaults ) throws Exception { if ( gleaner == null ) { gleaner = new QDoxComponentGleaner(); } return extract( configuration.sourceDirectories, configuration.sourceEncoding, getDefaultsByRole( roleDefaults ) ); } private List> extract( final List sourceDirectories, final String sourceEncoding, final Map> defaultsByRole ) throws Exception { assert sourceDirectories != null; assert defaultsByRole != null; List> descriptors = new ArrayList>(); // Scan the sources JavaDocBuilder builder = new JavaDocBuilder(); if ( StringUtils.isNotEmpty( sourceEncoding ) ) { builder.setEncoding( sourceEncoding ); } for ( String sourceDirectory : sourceDirectories ) { File dir = new File( sourceDirectory ); builder.addSourceTree( dir ); } JavaClass[] classes = builder.getClasses(); // For each class we find, try to glean off a descriptor for ( int i = 0; i < classes.length; i++ ) { ComponentDescriptor descriptor = gleaner.glean( builder, classes[i] ); if ( descriptor != null ) { applyDefaults( descriptor, defaultsByRole ); descriptors.add( descriptor ); } } return descriptors; } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescriptorExtractor.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescript0000644000175000017500000000226111124722742033532 0ustar twernertwerner/* * Copyright (C) 2007 the original author or authors. * * Licensed 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.codehaus.plexus.metadata; import java.util.List; import org.codehaus.plexus.component.repository.ComponentDescriptor; /** * An abstraction to allow pluggable {@link ComponentDescriptor} extraction to be dropped. * * @version $Id: ComponentDescriptorExtractor.java 7966 2008-12-25 15:25:22Z bentmann $ */ public interface ComponentDescriptorExtractor { String ROLE = ComponentDescriptorExtractor.class.getName(); List> extract( MetadataGenerationRequest configuration, ComponentDescriptor[] roleDefaults ) throws Exception; } ././@LongLink0000000000000000000000000000017200000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescriptorWriteException.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ComponentDescript0000644000175000017500000000333011053676131033531 0ustar twernertwernerpackage org.codehaus.plexus.metadata; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Trygve Laugstøl * @version $Id: ComponentDescriptorWriteException.java 7688 2008-08-23 02:56:25Z jvanzyl $ */ public class ComponentDescriptorWriteException extends Exception { public ComponentDescriptorWriteException( String message ) { super( message ); } public ComponentDescriptorWriteException( String message, Throwable cause ) { super( message, cause ); } public ComponentDescriptorWriteException( Throwable cause ) { super( cause ); } }plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/0000755000175000017500000000000011226720062030716 5ustar twernertwerner././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnInvocationHandler.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnInvocation0000644000175000017500000000501311075266577033430 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.util.Arrays; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnInvocationHandler implements InvocationHandler { private final Ann ann; private final ClassLoader cl; private final Class c; public AnnInvocationHandler(Ann ann, ClassLoader cl, Class c) { this.ann = ann; this.cl = cl; this.c = c; } public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { String name = m.getName(); if("toString".equals(name)) { StringBuffer sb = new StringBuffer(ann.getType()); sb.append("["); String sep = ""; for(Map.Entry e : ann.getParams().entrySet()) { // TODO conversion for class, array, enum, and annotation types sb.append(sep).append(e.getKey()+"="+e.getValue()); sep = "; "; } sb.append("]"); return sb.toString(); } Object value = ann.getParams().get(name); if(value!=null) { if(value instanceof Type) { String className = ((Type) value).getClassName(); try { return Class.forName(className, false, cl); } catch(ClassNotFoundException ex) { if(cl instanceof URLClassLoader) { URL[] urls = ((URLClassLoader) cl).getURLs(); throw new RuntimeException("Unable to load class " + className + " from " + Arrays.toString(urls), ex); } throw new RuntimeException("Unable to load class " + className + " from " + cl, ex); } } // TODO conversion for class, array, enum, and annotation types return value; } else { Method am = c.getDeclaredMethod(m.getName(), m.getParameterTypes()); return am.getDefaultValue(); } } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnReader.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnReader.jav0000644000175000017500000001524111144377236033274 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.Attribute; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.Label; import org.objectweb.asm.MethodVisitor; /** * @author Eugene Kuleshov */ public class AnnReader implements ClassVisitor { private final AnnClass annClass; private AnnReader(AnnClass annClass) { this.annClass = annClass; } public static AnnClass read(InputStream is, ClassLoader cl) throws IOException { AnnClass annClass = new AnnClass(cl); AnnReader cv = new AnnReader(annClass); ClassReader r = new ClassReader(is); r.accept(cv, ClassReader.SKIP_FRAMES | ClassReader.SKIP_CODE); return annClass; } public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { annClass.setName(name); annClass.setAccess(access); annClass.setSuperName(superName); annClass.setInterfaces(interfaces); } public AnnotationVisitor visitAnnotation(final String desc, boolean visible) { Ann ann = new Ann(desc); annClass.addAnn(ann); return new AnnAnnReader(ann); } public FieldVisitor visitField(int access, final String name, final String desc, String signature, Object value) { final AnnField field = new AnnField(annClass, access, name, desc); annClass.addField(field); return new FieldVisitor() { public AnnotationVisitor visitAnnotation(String desc, boolean visible) { Ann ann = new Ann(desc); field.addAnn(ann); return new AnnAnnReader(ann); } public void visitAttribute(Attribute attr) { } public void visitEnd() { } }; } public MethodVisitor visitMethod(int access, final String mname, final String mdesc, String signature, String[] exceptions) { final AnnMethod method = new AnnMethod(annClass, access, mname, mdesc); annClass.addMethod(method); return new MethodVisitor() { public AnnotationVisitor visitAnnotation(String desc, boolean visible) { Ann ann = new Ann(desc); method.addAnn(ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) { Ann ann = new Ann(desc); method.addParamAnn(parameter, ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitAnnotationDefault() { // TODO return null; } public void visitAttribute(Attribute attr) { } public void visitCode() { } public void visitFieldInsn(int opcode, String owner, String name, String desc) { } public void visitFrame(int type, int local, Object[] local2, int stack, Object[] stack2) { } public void visitIincInsn(int var, int increment) { } public void visitInsn(int opcode) { } public void visitIntInsn(int opcode, int operand) { } public void visitJumpInsn(int opcode, Label label) { } public void visitLabel(Label label) { } public void visitLdcInsn(Object cst) { } public void visitMethodInsn(int opcode, String owner, String name, String desc) { } public void visitMultiANewArrayInsn(String desc, int dims) { } public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) { } public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels) { } public void visitTypeInsn(int opcode, String type) { } public void visitVarInsn(int opcode, int var) { } public void visitMaxs(int maxStack, int maxLocals) { } public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) { } public void visitTryCatchBlock(Label start, Label end, Label handler, String type) { } public void visitLineNumber(int line, Label start) { } public void visitEnd() { } }; } public void visitInnerClass(String name, String outer, String inner, int access) { } public void visitOuterClass(String owner, String name, String desc) { } public void visitAttribute(Attribute attr) { } public void visitSource(String source, String debug) { } public void visitEnd() { } static class AnnAnnReader implements AnnotationVisitor { private Ann ann; public AnnAnnReader(Ann ann) { this.ann = ann; } public void visit(String name, Object value) { ann.addParam(name, value); } public void visitEnum(String name, String desc, String value) { ann.addParam(name, new AnnEnum(desc, value)); } public AnnotationVisitor visitAnnotation(String name, String desc) { Ann ann = new Ann(desc); this.ann.addParam(name, ann); return new AnnAnnReader(ann); } public AnnotationVisitor visitArray(String name) { return new AnnAnnArrayReader(ann, name); } public void visitEnd() { } } static class AnnAnnArrayReader implements AnnotationVisitor { private Ann ann; private String name; // TODO good enough for now, but does not cover general case private ArrayList array = new ArrayList(); public AnnAnnArrayReader(Ann ann, String name) { this.ann = ann; this.name = name; } public void visit(String name, Object value) { if(value instanceof String) { array.add((String) value); } } public AnnotationVisitor visitAnnotation(String name, String value) { return null; } public AnnotationVisitor visitArray(String arg0) { return null; } public void visitEnd() { ann.addParam(name, array.toArray(new String[array.size()])); } public void visitEnum(String arg0, String arg1, String arg2) { } } } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/Ann.java0000644000175000017500000000275511144377066032321 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.lang.reflect.Proxy; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class Ann { private String desc; private Map params = new LinkedHashMap(); public Ann(String desc) { this.desc = desc; } public void addParam(String name, Object value) { params.put(name, value); } public String getDesc() { return desc; } public String getType() { return Type.getType(desc).getClassName(); } public Map getParams() { return params; } @SuppressWarnings("unchecked") public T getAnnotation(Class c, ClassLoader cl) { return (T) Proxy.newProxyInstance(Ann.class.getClassLoader(), new Class[] { c }, // new AnnInvocationHandler(this, cl, c)); } } ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnMethod.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnMethod.jav0000644000175000017500000000454311075266577033325 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnMethod { private final AnnClass owner; private final int access; private final String name; private final String desc; private Map anns = new LinkedHashMap(); private Map> paramAnns = new HashMap>(); public AnnMethod(AnnClass owner, int access, String name, String desc) { this.owner = owner; this.access = access; this.name = name; this.desc = desc; } public int getAccess() { return access; } public String getName() { return name; } public String getDesc() { return desc; } public Map getAnns() { return anns; } public Map> getParamAnns() { return paramAnns; } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public void addParamAnn(int parameter, Ann ann) { Map anns = paramAnns.get(parameter); if(anns==null) { anns = new LinkedHashMap(); paramAnns.put(parameter, anns); } anns.put(ann.getDesc(), ann); } public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } public T getParameterAnnotation(int parameter, Class c) { Map anns = paramAnns.get(parameter); if (anns == null) { return null; } Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnField.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnField.java0000644000175000017500000000326611075266577033272 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.util.LinkedHashMap; import java.util.Map; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnField { private final AnnClass owner; private final int access; private final String name; private final String desc; private Map anns = new LinkedHashMap(); public AnnField(AnnClass owner, int access, String name, String desc) { this.owner = owner; this.access = access; this.desc = desc; this.name = name; } public int getAccess() { return access; } public String getName() { return name; } public String getDesc() { return desc; } public Map getAnns() { return anns; } public String getType() { return Type.getType(desc).getClassName(); } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, owner.getClassLoader()); } } ././@LongLink0000000000000000000000000000014500000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnClass.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnClass.java0000644000175000017500000000576511075266577033322 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnClass { private int access; private String name; private String superName; private String[] interfaces; private Map anns = new LinkedHashMap(); private Map fields = new LinkedHashMap(); private Map methods = new LinkedHashMap(); private ClassLoader cl; // setters public AnnClass(ClassLoader cl) { this.cl = cl; } public void setName(String name) { this.name = name; } public void setAccess(int access) { this.access = access; } public void setSuperName(String superName) { this.superName = superName; } public void setInterfaces(String[] interfaces) { this.interfaces = interfaces; } public void addAnn(Ann ann) { anns.put(ann.getDesc(), ann); } public void addField(AnnField field) { fields.put(field.getName(), field); } public void addMethod(AnnMethod method) { methods.put(method.getName() + method.getDesc(), method); } // getters public ClassLoader getClassLoader() { return cl; } public int getAccess() { return access; } public String getName() { return name; } public String getSuperName() { return superName; } public String[] getInterfaces() { return interfaces; } public Map getAnns() { return anns; } public Map getFields() { return fields; } public Map getMethods() { return methods; } public Set getFieldNames() { return fields.keySet(); } public Set getMethodKeys() { return methods.keySet(); } // conversion to java.lang.Annotation public T getAnnotation(Class c) { Ann ann = anns.get(Type.getDescriptor(c)); return ann == null ? null : ann.getAnnotation(c, cl); } public T getFieldAnnotation(String fieldName, Class c) { AnnField field = fields.get(fieldName); return field==null ? null : field.getAnnotation(c); } public T getMethodAnnotation(String methodKey, Class c) { AnnMethod method = methods.get(methodKey); return method==null ? null : method.getAnnotation(c); } } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/ann/AnnEnum.java0000644000175000017500000000334111075233331033123 0ustar twernertwerner/* * Copyright (C) 2008 the original author or authors. * * Licensed 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.codehaus.plexus.metadata.ann; import org.objectweb.asm.Type; /** * @author Eugene Kuleshov */ public class AnnEnum { private final String desc; private final String value; public AnnEnum(String desc, String value) { this.desc = desc; this.value = value; } public String getDesc() { return desc; } public String getValue() { return value; } public String getType() { return Type.getType(desc).getClassName(); } public int hashCode() { return 31 * (31 + desc.hashCode()) + value.hashCode(); } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } AnnEnum other = (AnnEnum) obj; if (desc == null) { if (other.desc != null) { return false; } } else if (!desc.equals(other.desc)) { return false; } if (value == null) { if (other.value != null) { return false; } } else if (!value.equals(other.value)) { return false; } return true; } } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/DefaultMetadataGenerator.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/metadata/DefaultMetadataGe0000644000175000017500000001337311126642046033401 0ustar twernertwernerpackage org.codehaus.plexus.metadata; /* * The MIT License * * Copyright (c) 2004-2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.component.repository.ComponentDependency; import org.codehaus.plexus.component.repository.ComponentDescriptor; import org.codehaus.plexus.component.repository.ComponentSetDescriptor; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.metadata.gleaner.AnnotationComponentGleaner; import org.codehaus.plexus.metadata.merge.Merger; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; /** * @author Jason van Zyl */ @Component(role = MetadataGenerator.class) public class DefaultMetadataGenerator extends AbstractLogEnabled implements MetadataGenerator { @Requirement private Merger merger; private ComponentDescriptor[] roleDefaults; // should be a component private ComponentDescriptorExtractor[] extractors; // should be a component private ComponentDescriptorWriter writer = new DefaultComponentDescriptorWriter(); public void generateDescriptor( MetadataGenerationRequest request ) throws Exception { assert request.outputFile != null; if ( extractors == null || extractors.length == 0 ) { extractors = new ComponentDescriptorExtractor[] { new SourceComponentDescriptorExtractor(), new ClassComponentDescriptorExtractor( new AnnotationComponentGleaner() ) }; } List> descriptors = new ArrayList>(); for ( int i = 0; i < extractors.length; i++ ) { try { List> list = extractors[i].extract( request, roleDefaults ); if ( list != null && !list.isEmpty() ) { descriptors.addAll( list ); } } catch ( Exception e ) { throw new Exception( "Failed to extract descriptors", e ); } } List componentDescriptors = new ArrayList(); // // If we found descriptors, write out the discovered descriptors // if ( descriptors.size() > 0 ) { getLogger().info( "Discovered " + descriptors.size() + " component descriptors(s)" ); ComponentSetDescriptor set = new ComponentSetDescriptor(); set.setComponents( descriptors ); set.setDependencies( Collections. emptyList() ); if ( request.componentDescriptorDirectory == null ) { writeDescriptor( set, request.outputFile ); } else { if ( request.intermediaryFile == null ) { request.intermediaryFile = File.createTempFile( "plexus-metadata", "xml" ); request.intermediaryFile.deleteOnExit(); } writeDescriptor( set, request.intermediaryFile ); componentDescriptors.add( request.intermediaryFile ); } } // // Deal with merging // if ( request.componentDescriptorDirectory != null && request.componentDescriptorDirectory.isDirectory() ) { File[] files = request.componentDescriptorDirectory.listFiles(); for ( File file : files ) { if ( file.getName().endsWith( ".xml" ) && !file.getName().equals( "plexus.xml" ) ) { componentDescriptors.add( file ); } } } if ( componentDescriptors.size() > 0 ) { merger.mergeDescriptors( request.outputFile, componentDescriptors ); } } private void writeDescriptor( ComponentSetDescriptor desc, File outputFile ) throws Exception { assert desc != null; assert outputFile != null; FileUtils.forceMkdir( outputFile.getParentFile() ); BufferedWriter output = new BufferedWriter( new OutputStreamWriter( new FileOutputStream( outputFile ), "UTF-8" ) ); try { writer.writeDescriptorSet( output, desc, false ); output.flush(); } finally { IOUtil.close( output ); } getLogger().debug( "Wrote: " + outputFile ); } } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/0000755000175000017500000000000011226720062030364 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/0000755000175000017500000000000011226720062032603 5ustar twernertwerner././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirement.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/Compo0000644000175000017500000001071111074742745033620 0ustar twernertwernerpackage org.codehaus.plexus.component.repository; import org.codehaus.plexus.PlexusConstants; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed 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. */ /** * This represents a component this is required by another component. * * @author Michal Maczka * @version $Id: ComponentRequirement.java 6965 2007-10-21 05:32:27Z jvanzyl $ */ public class ComponentRequirement { private String role; private String roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; private String fieldName; private String fieldMappingType; /** * Returns the field name that this component requirement will inject. * @return the field name that this component requirement will inject */ public String getFieldName() { return fieldName; } /** * Sets the name of the field that will be populated by the required * component. * @param fieldName the name of the field to be populated */ public void setFieldName( String fieldName ) { this.fieldName = fieldName; } /** * Returns the role of the required component. * @return the role of the required component */ public String getRole() { return role; } /** * Sets the role of the require component. * @param role the required component's role */ public void setRole( String role ) { this.role = role; } /** * Returns the role-hint of the required component. * @return the role-hint of the required component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of the require component. * Pasing null will set the hint to the default value. * @param roleHint the required component's role-hint */ public void setRoleHint( String roleHint ) { if ( roleHint == null || roleHint.trim().equals( "" ) ) { this.roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } else { this.roleHint = roleHint; } } /** * Returns the type of the field this component requirement will inject. * @return the type of the field this component requirement will inject */ public String getFieldMappingType() { return fieldMappingType; } /** * Sets the type of the field that will be populated by the required * component. * @param fieldType the type of the field to be populated */ public void setFieldMappingType( String fieldType ) { this.fieldMappingType = fieldType; } public String toString() { return "ComponentRequirement{" + "role='" + getRole() + "'" + ", " + "roleHint='" + getRoleHint() + "', " + "fieldName='" + getFieldName() + "'" + "}"; } /** * Returns a human-friendly key, suitable for display. * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '").append( getRole() ).append( "'" ); if ( getRoleHint() != null ) { key.append( ", role-hint: '" ).append( getRoleHint() ).append( "'. " ); } if ( getFieldName() != null ) { key.append( ", field name: '" ).append( getFieldName() ).append( "' " ); } return key.toString(); } public boolean equals( Object other ) { if ( other instanceof ComponentRequirement ) { String myId = role + ":" + roleHint; ComponentRequirement req = (ComponentRequirement) other; String otherId = req.role + ":" + req.roleHint; return myId.equals( otherId ); } return false; } public int hashCode() { return ( role + ":" + roleHint ).hashCode(); } } ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/ComponentSetDescriptor.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/Compo0000644000175000017500000001073011107623200033576 0ustar twernertwernerpackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed 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.util.ArrayList; import java.util.List; /** * Contains a set of ComponentDescriptors and the set's dependencies. * * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ComponentSetDescriptor.java 7828 2008-11-14 22:07:56Z dain $ */ public class ComponentSetDescriptor { // This field is not currently used in Maven, or Plexus private String id; /** The source location of this component source descriptor */ private String source; /** Flag to indicate whether this component should be loaded in a realm/classloader of its own. */ private boolean isolatedRealm; /** The component descriptors that can be found within this component set descriptor. */ private final List> components = new ArrayList>(); /** The dependencies that are required by the set of components found in this component set descriptor. */ private final List dependencies = new ArrayList(); /** * Returns a list of components in this set. * @return a list of components */ public List> getComponents() { return components; } /** * Add a new ComponentDescriptor to this set. * @param cd the ComponentDescriptor to add */ public void addComponentDescriptor( ComponentDescriptor cd ) { components.add( cd ); } /** * Sets a List of components as this set's contents. * @param components the List of components to set */ public void setComponents( List> components ) { this.components.clear(); this.components.addAll(components); } /** * Returns a List of dependencies of this set of components. * @return a List of dependencies of this set of components */ public List getDependencies() { return dependencies; } /** * Add a depenency to this set's contents. * @param cd the ComponentDependency to add */ public void addDependency( ComponentDependency cd ) { dependencies.add( cd ); } /** * Sets a List of dependencies as this set's component dependencies. * @param dependencies the List of components to set */ public void setDependencies( List dependencies ) { this.dependencies.clear(); this.dependencies.addAll(dependencies); } /** * Sets that this set of components may be in an isolated classrealm. * @param isolatedRealm true if this set of components may be in an * isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns true if this set may be in an isolated classrealm. * @return true if this set may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Returns the identifier of this set. * @return the identifier of this set */ public String getId() { return id; } /** * Sets the identifier of this set. * @param id the identifier to set */ public void setId( String id ) { this.id = id; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append( "Component Descriptor: " ); for ( ComponentDescriptor cd : components ) { sb.append( cd.getHumanReadableKey() ).append( "\n" ); } sb.append( "---" ); return sb.toString(); } public String getSource() { return source; } public void setSource( String source ) { this.source = source; } } ././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/README.txtplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/READM0000644000175000017500000000032411074742745033372 0ustar twernertwernerThis package contains some classes copied from the container before it started using the "default" role hints. This can be removed once all supported maven versions are using a container newer than 1.0-alpha-19.././@LongLink0000000000000000000000000000017500000000000011570 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/ComponentRequirementList.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/Compo0000644000175000017500000000152611107623200033601 0ustar twernertwernerpackage org.codehaus.plexus.component.repository; import java.util.List; /** * Created by IntelliJ IDEA. * * @author Andrew Williams * @version $Id: ComponentRequirementList.java 7828 2008-11-14 22:07:56Z dain $ * @since 1.0 */ public class ComponentRequirementList extends ComponentRequirement { private List roleHints; public List getRoleHints() { return roleHints; } public void setRoleHints(List roleHints) { this.roleHints = roleHints; } public String getRoleHint() { StringBuffer buffer = new StringBuffer(); for ( String hint : roleHints ) { if (buffer.length() > 0) { buffer.append(","); } buffer.append(hint); } return buffer.toString(); } } ././@LongLink0000000000000000000000000000017000000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/ComponentDescriptor.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/component/repository/Compo0000644000175000017500000004401311175110715033606 0ustar twernertwernerpackage org.codehaus.plexus.component.repository; /* * Copyright 2001-2006 Codehaus Foundation. * * Licensed 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 org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.codehaus.plexus.configuration.PlexusConfiguration; import java.util.ArrayList; import java.util.List; import java.util.Arrays; import java.util.Collections; /** * Component instantiation description. * * @author Jason van Zyl * @author bob mcwhirter * @author Michal Maczka * @version $Id: ComponentDescriptor.java 8155 2009-04-26 01:22:53Z jvanzyl $ */ public class ComponentDescriptor { private String alias = null; private String role = null; private Class roleClass; private String roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; private String implementation; private Class implementationClass; private String version; private String componentType; private PlexusConfiguration configuration; private String instantiationStrategy; private String lifecycleHandler; private String componentProfile; private final List requirements = new ArrayList(); private String componentFactory; private String componentComposer; private String componentConfigurator; private String description; private ClassRealm realm; // ---------------------------------------------------------------------- // These two fields allow for the specification of an isolated class realm // and dependencies that might be specified in a component configuration // setup by a user i.e. this is here to allow isolation for components // that are not picked up by the discovery mechanism. // ---------------------------------------------------------------------- private boolean isolatedRealm; // ---------------------------------------------------------------------- private ComponentSetDescriptor componentSetDescriptor; private String source; // ---------------------------------------------------------------------- // Instance methods // ---------------------------------------------------------------------- public ComponentDescriptor() { } public ComponentDescriptor( Class implementationClass, ClassRealm realm ) { this.implementationClass = implementationClass; this.implementation = implementationClass.getName(); this.realm = realm; } /** * The location this information came from (descriptor file URI). */ public void setSource( String source ) { this.source = source; } /** * The location this information came from (descriptor file URI). */ public String getSource() { return source; } /** * Returns a human-friendly key, suitable for display. * * @return a human-friendly key */ public String getHumanReadableKey() { StringBuffer key = new StringBuffer(); key.append( "role: '" ).append( role ).append( "'" ); key.append( ", implementation: '" ).append( implementation ).append( "'" ); if ( roleHint != null ) { key.append( ", role hint: '" ).append( roleHint ).append( "'" ); } if ( alias != null ) { key.append( ", alias: '" ).append( alias ).append( "'" ); } return key.toString(); } /** * Returns an alias for this component. An alias as an alternate name other than the normal key. * * @return an alias for this component */ public String getAlias() { return alias; } /** * Sets the alias for this component. * * @param alias alternate name to set */ public void setAlias( String alias ) { this.alias = alias; } /** * Returns the role of this component. * * @return the role of this component */ public String getRole() { return role; } public Class getRoleClass() { attemptRoleLoad(); if (roleClass == null) { return (Class) Object.class; } return roleClass; } private void attemptRoleLoad() { if ( roleClass == null && role != null && realm != null ) { try { roleClass = realm.loadClass( role ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } /** * Sets the role of this component. * * @param role this component's role */ public void setRole( String role ) { this.role = role; // reload role class roleClass = null; attemptRoleLoad(); } public void setRoleClass( Class roleClass ) { this.roleClass = roleClass; if (roleClass == null) { role = null; } else { role = roleClass.getName(); } } /** * Returns the role-hint of this component. * * @return the role-hint of this component */ public String getRoleHint() { return roleHint; } /** * Sets the role-hint of this component. Pasing null will set the hint to the default value. * * @param roleHint this component's role-hint */ public void setRoleHint( String roleHint ) { if ( ( roleHint == null ) || roleHint.trim().equals( "" ) ) { this.roleHint = PlexusConstants.PLEXUS_DEFAULT_HINT; } else { this.roleHint = roleHint; } } /** * Returns the implementation of this componet. Implementation is a string denoting a FQCN in normal Java * components, or some other name or file for other component factory implementations. * * @return the implementation of this componet's role. */ public String getImplementation() { return implementation; } /** * Sets the implementation of this componet. * * @param implementation string denoting a FQCN in normal Java components, or some other name or file for other * component factory implementations */ public void setImplementation( String implementation ) { this.implementation = implementation; // reload implementation class implementationClass = null; attemptImplementationLoad(); } /** * Returns the implementation class of this componet, or null if the implementation class can not be loaded. * * @return the implementation of this componet's role. */ public Class getImplementationClass() { attemptImplementationLoad(); if (implementationClass == null) { return (Class) Object.class; } return implementationClass; } private void attemptImplementationLoad() { if ( implementationClass == null && implementation != null && realm != null ) { try { implementationClass = realm.loadClass( implementation ); Thread.currentThread(); } catch ( Throwable ignored ) { Thread.currentThread(); } } } public void setImplementationClass( Class implementationClass ) { this.implementationClass = implementationClass; if (implementationClass == null) { implementation = null; } else { implementation = implementationClass.getName(); } } /** * Returns a specific point in a components's project timeline. i.e. version 1, or 2.1.4 * * @return a specific point in a components's project timeline */ public String getVersion() { return version; } /** * Sets the point in a components's project development timeline * * @param version the components's version */ public void setVersion( String version ) { this.version = version; } /** * Returns the type of this component. * * @return the type of this component */ public String getComponentType() { return componentType; } /** * Sets this component's type. * * @param componentType the type to set */ public void setComponentType( String componentType ) { this.componentType = componentType; } /** * Returns the type of instantiation strategy for this component. * * @return the type of instantiation strategy for this component */ public String getInstantiationStrategy() { return instantiationStrategy; } /** * Returns configuration values defined for this component. * * @return configuration values defined for this component */ public PlexusConfiguration getConfiguration() { return configuration; } /** * Sets the configuration hierarchy for this component. * * @param configuration the configuration hierarchy to set */ public void setConfiguration( PlexusConfiguration configuration ) { this.configuration = configuration; } /** * Returns true if this component has a configuration. * * @return true if this component has a configuration */ public boolean hasConfiguration() { return configuration != null; } /** * Returns the lifecycle-handler for this component. * * @return the lifecycle-handler for this component */ public String getLifecycleHandler() { return lifecycleHandler; } /** * Sets the lifecycle-handler for this component. For example, "basic", "passive", "bootstrap". * * @param lifecycleHandler the lifecycle handler string to set */ public void setLifecycleHandler( String lifecycleHandler ) { this.lifecycleHandler = lifecycleHandler; } public String getComponentProfile() { return componentProfile; } public void setComponentProfile( String componentProfile ) { this.componentProfile = componentProfile; } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement requirement ) { this.requirements.add( requirement ); } /** * Add a project requirement to this component. * * @param requirement the requirement to add */ public void addRequirement( ComponentRequirement... requirement ) { this.requirements.addAll( Arrays.asList( requirement )); } /** * Adds a list of requirements to this component. * * @param requirements the requirements to add */ public void addRequirements( List requirements ) { this.requirements.addAll( requirements ); } /** * Remove a project requirement from this component. * * @param requirement the requirement to remove */ public void removeRequirement( ComponentRequirement... requirement ) { this.requirements.removeAll( Arrays.asList( requirement )); } /** * Removes a list of requirements from this component. * * @param requirements the requirements to remove */ public void removeRequirements( List requirements ) { this.requirements.removeAll( requirements ); } /** * Returns all project requirements of this component. * * @return all project requirements of this component */ public List getRequirements() { return Collections.unmodifiableList( requirements ); } /** * Returns an id of the factory used to create this component. * * @return an id of the factory used to create this component */ public String getComponentFactory() { return componentFactory; } /** * Sets the id of the factory to use to create this component. For example, "jruby" will use a JRuby factory. * * @param componentFactory */ public void setComponentFactory( String componentFactory ) { this.componentFactory = componentFactory; } /** * Returns the ID of the type of composer this component will use. For example, "setter" or "field" for the * different types of dependency injection. * * @return the ID of the type of composer this component will use */ public String getComponentComposer() { return componentComposer; } /** * Sets a representation of the composer this component uses. * * @param componentComposer string representation of the composer to use */ public void setComponentComposer( String componentComposer ) { this.componentComposer = componentComposer; } /** * Return a human-readable description of this component. * * @return a human-readable description of this component */ public String getDescription() { return description; } /** * Sets a description of this component for users to read. * * @param description a human-readable description of this component */ public void setDescription( String description ) { this.description = description; } /** * Sets the instantiation-strategy for this component. For example, "container". * * @param instantiationStrategy */ public void setInstantiationStrategy( String instantiationStrategy ) { this.instantiationStrategy = instantiationStrategy; } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- /** * Returns true if this may be in an isolated classrealm. * * @return true if this may be in an isolated classrealm */ public boolean isIsolatedRealm() { return isolatedRealm; } /** * Sets the component set descriptor of components and dependencies for this component. * * @param componentSetDescriptor the component set descriptor of components and dependencies */ public void setComponentSetDescriptor( ComponentSetDescriptor componentSetDescriptor ) { this.componentSetDescriptor = componentSetDescriptor; } /** * Returns the component set descriptor. * * @return the component set descriptor */ public ComponentSetDescriptor getComponentSetDescriptor() { return componentSetDescriptor; } /** * Sets that this component may be in an isolated classrealm. * * @param isolatedRealm true if this component may be in an isolated classrealm */ public void setIsolatedRealm( boolean isolatedRealm ) { this.isolatedRealm = isolatedRealm; } /** * Returns the type of component configurator for this project. For example "basic" for normal, or "map-oriented" * for map oriented components. * * @return the type of component configurator for this project */ public String getComponentConfigurator() { return componentConfigurator; } /** * Sets the type of component configurator for this project. * * @param componentConfigurator */ public void setComponentConfigurator( String componentConfigurator ) { this.componentConfigurator = componentConfigurator; } /** * The ClassRealm that this component lives under. * * @return ClassRealm that this component lives under */ public ClassRealm getRealm() { return realm; } /** * Set the ClassRealm that this component lives under. * * @param realm the ClassRealm that this component lives under */ public void setRealm( ClassRealm realm ) { this.realm = realm; // reload implementation class implementationClass = null; attemptImplementationLoad(); // reload role class roleClass = null; attemptRoleLoad(); } // Component identity established here! public boolean equals( Object other ) { if ( !( other instanceof ComponentDescriptor ) ) { return false; } else { ComponentDescriptor otherDescriptor = (ComponentDescriptor) other; boolean isEqual = true; String role = getRole(); String otherRole = otherDescriptor.getRole(); isEqual = isEqual && ( ( role.equals( otherRole ) ) || role.equals( otherRole ) ); String roleHint = getRoleHint(); String otherRoleHint = otherDescriptor.getRoleHint(); isEqual = isEqual && ( ( roleHint.equals( otherRoleHint ) ) || roleHint.equals( otherRoleHint ) ); return isEqual; } } public String toString() { return getClass().getName() + " [role: '" + getRole() + "', hint: '" + getRoleHint() + "', realm: " + ( realm == null ? "NULL" : "'" + realm + "'" ) + "]"; } public int hashCode() { int result = getRole().hashCode() + 1; String hint = getRoleHint(); if ( hint != null ) { result += hint.hashCode(); } return result; } } plexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/0000755000175000017500000000000011226720062027470 5ustar twernertwernerplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/0000755000175000017500000000000011226720062030766 5ustar twernertwerner././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusMergeMojo.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusMergeMo0000644000175000017500000000525211126637653033465 0ustar twernertwernerpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2006, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.merge.Merger; /** * Merges a set of Plexus descriptors into one descriptor file. * * @goal merge-metadata * @phase process-classes * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusMergeMojo.java 7986 2008-12-31 09:47:23Z bentmann $ */ public class PlexusMergeMojo extends AbstractMojo { /** * The destination for the merged descriptor. * * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml" * @required */ private File output; /** * The paths of the input descriptors to merge. * * @parameter */ private File[] descriptors; /** @component role-hint="componentsXml" */ private Merger merger; public void execute() throws MojoExecutionException { List files = new ArrayList(); if ( descriptors != null ) { files.addAll( Arrays.asList( descriptors ) ); } if ( files.isEmpty() ) { return; } try { merger.mergeDescriptors( output, files ); } catch ( IOException e ) { throw new MojoExecutionException( "Error while executing component descritor creator.", e ); } } } ././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/AbstractDescriptorMojo.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/AbstractDescr0000644000175000017500000000363511125011135033434 0ustar twernertwernerpackage org.codehaus.plexus.maven.plugin; /* * The MIT License * * Copyright (c) 2004-2006, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.metadata.MetadataGenerator; /** * @author Jason van Zyl */ public abstract class AbstractDescriptorMojo extends AbstractMojo { /** * @parameter expression="${project}" * @required * @readonly */ protected MavenProject mavenProject; /** * The file encoding of the source files. * * @parameter default-value="${project.build.sourceEncoding}" */ protected String sourceEncoding; /** @component */ protected MavenProjectHelper mavenProjectHelper; /** @component */ protected MetadataGenerator metadataGenerator; } ././@LongLink0000000000000000000000000000016100000000000011563 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusDescriptorMojo.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusDescrip0000644000175000017500000000673211126637653033527 0ustar twernertwernerpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.MetadataGenerationRequest; /** * Generates a Plexus components.xml component descriptor file from source (javadoc) or * class annotations. * * @goal generate-metadata * @phase process-classes * @requiresDependencyResolution compile * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusDescriptorMojo.java 7986 2008-12-31 09:47:23Z bentmann $ */ public class PlexusDescriptorMojo extends AbstractDescriptorMojo { /** * The output location for the generated descriptor. * * @parameter default-value="${project.build.outputDirectory}/META-INF/plexus/components.xml" * @required */ protected File generatedMetadata; /** * The location of manually crafted component descriptors. The contents of the descriptor files in this directory is * merged with the information extracted from the project's sources/classes. * * @parameter default-value="${basedir}/src/main/resources/META-INF/plexus" * @required */ protected File staticMetadataDirectory; /** * The output location for the intermediary descriptor. This descriptors contains only the information extracted * from the project's sources/classes. * * @parameter default-value="${project.build.directory}/components.xml" * @required */ protected File intermediaryMetadata; public void execute() throws MojoExecutionException { MetadataGenerationRequest request = new MetadataGenerationRequest(); try { request.classpath = mavenProject.getCompileClasspathElements(); request.classesDirectory = new File( mavenProject.getBuild().getOutputDirectory() ); request.sourceDirectories = mavenProject.getCompileSourceRoots(); request.sourceEncoding = sourceEncoding; request.componentDescriptorDirectory = staticMetadataDirectory; request.intermediaryFile = intermediaryMetadata; request.outputFile = generatedMetadata; metadataGenerator.generateDescriptor( request ); } catch ( Exception e ) { throw new MojoExecutionException( "Error generating metadata: ", e ); } } } ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusTestDescriptorMojo.javaplexus-component-metadata-1.0~beta3.0.7/src/main/java/org/codehaus/plexus/maven/plugin/PlexusTestDes0000644000175000017500000000703611126643123033474 0ustar twernertwernerpackage org.codehaus.plexus.maven.plugin; /* * Copyright (c) 2004-2005, Codehaus.org * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and * associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.File; import org.apache.maven.plugin.MojoExecutionException; import org.codehaus.plexus.metadata.MetadataGenerationRequest; /** * Generates a Plexus components.xml component descriptor file from test source (javadoc) * or test class annotations. * * @goal generate-test-metadata * @phase process-test-classes * @requiresDependencyResolution test * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: PlexusTestDescriptorMojo.java 7988 2008-12-31 10:15:47Z bentmann $ */ public class PlexusTestDescriptorMojo extends AbstractDescriptorMojo { /** * The output location for the generated descriptor. * * @parameter default-value="${project.build.testOutputDirectory}/META-INF/plexus/components.xml" * @required */ protected File testGeneratedMetadata; /** * The location of manually crafted component descriptors. The contents of the descriptor files in this directory is * merged with the information extracted from the project's sources/classes. * * @parameter default-value="${basedir}/src/test/resources/META-INF/plexus" * @required */ protected File testStaticMetadataDirectory; /** * The output location for the intermediary descriptor. This descriptors contains only the information extracted * from the project's sources/classes. * * @parameter default-value="${project.build.directory}/test-components.xml" * @required */ protected File testIntermediaryMetadata; public void execute() throws MojoExecutionException { MetadataGenerationRequest request = new MetadataGenerationRequest(); try { request.classpath = mavenProject.getTestClasspathElements(); request.classesDirectory = new File( mavenProject.getBuild().getTestOutputDirectory() ); request.sourceDirectories = mavenProject.getTestCompileSourceRoots(); request.sourceEncoding = sourceEncoding; request.componentDescriptorDirectory = testStaticMetadataDirectory; request.intermediaryFile = testIntermediaryMetadata; request.outputFile = testGeneratedMetadata; metadataGenerator.generateDescriptor( request ); } catch ( Exception e ) { throw new MojoExecutionException( "Error generating test metadata: ", e ); } } } plexus-component-metadata-1.0~beta3.0.7/pom.xml0000644000175000017500000000776011202563456021361 0ustar twernertwerner 4.0.0 org.codehaus.plexus plexus-containers 1.0-beta-3.0.7 plexus-component-metadata maven-plugin Plexus :: Component Metadata A Maven plugin to generate Plexus descriptors from source tags and class annotations. org.codehaus.plexus plexus-container-default org.codehaus.plexus plexus-component-annotations org.codehaus.plexus plexus-utils com.thoughtworks.qdox qdox jdom jdom org.apache.maven maven-plugin-api org.apache.maven maven-model org.apache.maven maven-project org.codehaus.plexus plexus-cli 1.2 commons-cli commons-cli 1.0 asm asm 3.1 org.apache.maven.plugins maven-plugin-plugin 2.4.2 its maven-invoker-plugin 1.3 true src/it ${project.build.directory}/it annotation-processing-test/* setup validate ${project.build.directory}/local-repo src/it/settings.xml clean process-classes integration-test install run