directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From oer...@apache.org
Subject svn commit: r518765 [5/7] - in /directory/sandbox/oersoy/rpm.factory.parent: ./ rpm.factory.archetype/ rpm.factory.archetype/.settings/ rpm.factory.archetype/src/ rpm.factory.archetype/src/main/ rpm.factory.archetype/src/main/resources/ rpm.factory.arc...
Date Thu, 15 Mar 2007 21:50:37 GMT
Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojo.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojo.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojo.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojo.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,501 @@
+package org.apache.maven.plugins.rpm.factory.mojo;
+
+/*
+ * Copyright 2001-2005 The Apache Software 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.apache.commons.io.FileUtils;
+import org.apache.commons.vfs.FileObject;
+import org.apache.maven.plugin.logging.Log;
+
+import org.apache.maven.model.emf.metadata.v200.MetaData;
+import org.apache.maven.model.emf.metadata.v200.MetadataV200Factory;
+import org.apache.maven.model.emf.metadata.v200.Project;
+import org.apache.maven.model.emf.pom.v400.Dependency;
+import org.apache.maven.model.emf.pom.v400.License;
+import org.apache.maven.model.emf.pom.v400.LicensesType;
+import org.apache.maven.model.emf.pom.v400.Model;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.build.ArtifactIdToResourceMapBuilder;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.build.MetadataListBuilder;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.filter.DependencyFilter;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize.DependencyInitializer;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize.ProjectInitializer;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize.ResourceSetInitializer;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.load.MetadataResourceLoad;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.load.PomLoad;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.transform.MetadataV1ToMetadataV2Transform;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.transform.Pom2SpecTransform;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.validate.LibrarySpecValidator;
+import org.apache.maven.rpm.factory.model.spec.v100.LibrarySpecDescriptor;
+import org.apache.maven.rpm.factory.spec.generators.LibrarySpecGenerator;
+import org.apache.tuscany.model.emf.ecore2ecore.MappingRoot;
+import org.apache.tuscany.model.emf.processor.ecore2ecore.impl.Ecore2EcoreProcessor;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 
+ * Goal that reads a maven-metadata.xml file and generates
+ * binary rpms for all the library artifacts listed in the file.
+ * 
+ * @goal generate
+ * 
+ * @phase generate-sources
+ * 
+ * TODO - Write the pom that is included with the RPM so that it has the
+ * parent values set on it.
+ */
+public class RPMFactoryMojo
+    extends AbstractMojo
+    implements RPMFactoryMojoConstants
+{
+	/** @parameter default-value="${basedir}  */
+	private File baseDirectory;
+	
+    /** @parameter */
+    private File repositoryBaseDirectory;
+
+    /** @parameter */
+    private File aggregatedMetadataTargetStorageDirectory;
+    
+    /** @parameter */
+    private Boolean aggregatedMetadataPersisted;
+    
+    /** @parameter */
+    private Boolean rpmGenerationEnabled;
+    
+    /** @parameter */
+    private String rpmTopDirectoryPath;
+    
+    /** @parameter */
+    private String rpmTmpDirectoryPath;
+    
+    /** @parameter */
+    private String rpmBuildDirectoryPath;
+
+    /** @parameter */
+    private String rpmSpecsDirectoryPath;
+    
+    /** @parameter */
+    private String rpmRpmsDirectoryPath;
+
+    private MetadataV200Factory metadataV200Factory= MetadataV200Factory.eINSTANCE;
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        
+        //TODO Check that the directories are valid.  Input parameter validation.
+        getLog().info( "========================================================== ");
+        getLog().info( "Repository Base Directory: " + repositoryBaseDirectory.toString() );
+        getLog().info( "========================================================== \n");
+    
+        getLog().info( "========================================================== ");
+        getLog().info( "Aggregated Metadata Storage Directory: " + 
+            aggregatedMetadataTargetStorageDirectory.toString() );
+        getLog().info( "========================================================== \n");
+
+        getLog().info( "========================================================== ");
+        getLog().info( "RPM Top Directory: " +  rpmTopDirectoryPath );
+        getLog().info( "========================================================== \n");
+
+        
+        getLog().info( "========================================================== ");
+        getLog().info( "Is Aggregate Meta Data Persisted: " +  aggregatedMetadataPersisted.toString() );
+        getLog().info( "========================================================== \n");
+
+        getLog().info( "========================================================== ");
+        getLog().info( "Is RPM Generation Enabled: " +  rpmGenerationEnabled.toString() );
+        getLog().info( "========================================================== \n");
+
+
+        FileObject[] metadataFiles =
+            MetadataListBuilder.discoverMetadata(repositoryBaseDirectory);
+
+        ResourceSet resourceSetV1 = 
+            ResourceSetInitializer.getInitializedMetadataV100ResourceSet();
+
+        List<Resource> resources = MetadataResourceLoad.getMetadataResources(
+                    metadataFiles, 
+                    resourceSetV1);
+        
+        
+        
+        MappingRoot mappingRoot     = MetadataV1ToMetadataV2Transform.createMetadataV1ToMetadataV2MappingRoot();
+
+        MetaData metadataV2         = metadataV200Factory.createMetaData();
+
+        EList<Project> projects = metadataV2.getProjects();
+        
+        Iterator<Resource> resourceIterator = resources.iterator();
+        
+        while(resourceIterator.hasNext())
+        {
+            Resource resource = resourceIterator.next();
+
+            EObject metadata  = resource.getEObject(METADATA_FRAGMENT_PATH);
+            
+            EObject project   = Ecore2EcoreProcessor.execute(metadata, mappingRoot);
+         
+            projects.add( (Project) project );
+        }
+
+        
+        //TODO Consider removing the whole thing
+        //We could just use the metadata files directly if we do not want to write the consolidated metadata
+        if (aggregatedMetadataPersisted)
+        {
+            ResourceSet resourceSetV2 = 
+                ResourceSetInitializer.
+                getInitializedMetadataV200ResourceSet();
+            
+            Resource resourceV2 = 
+                resourceSetV2.
+                createResource(
+                    URI.createFileURI(
+                        aggregatedMetadataTargetStorageDirectory.getAbsolutePath()
+                        + "/" 
+                        + MAVEN_REPOSITORY_METADATA_VERSION_2_FILE_NAME) );
+            
+            resourceV2.getContents().add( metadataV2 );
+
+            try
+            {
+                aggregatedMetadataTargetStorageDirectory.mkdirs();
+                resourceV2.save(null);
+            }
+            catch ( IOException e )
+            {
+                throw new MojoExecutionException("Could not save aggregated metadata.");
+            }   
+        }
+        
+        if (rpmGenerationEnabled)
+        {
+            File rpmBuildContainerDirectory = new File(
+                baseDirectory.getAbsolutePath(), 
+                rpmTopDirectoryPath);
+            
+            File tmpDirectory = new File(
+                rpmBuildContainerDirectory.getAbsolutePath(), rpmTmpDirectoryPath); 
+
+            File buildDirectory = new File(
+                rpmBuildContainerDirectory.getAbsolutePath(), rpmBuildDirectoryPath); 
+
+            File specsDirectory = new File(
+                rpmBuildContainerDirectory.getAbsolutePath(), rpmSpecsDirectoryPath); 
+
+            File rpmsDirectory = new File(
+                rpmBuildContainerDirectory.getAbsolutePath(), rpmRpmsDirectoryPath);
+            
+            try {
+                FileUtils.deleteDirectory(rpmBuildContainerDirectory);
+            } catch (IOException e) 
+            {
+                getLog().error("-----------------------------------------------------------\n");
+                getLog().error("The root rpm build directory: " + rpmBuildContainerDirectory.getAbsolutePath() + " could not be deleted.");
+                getLog().error("-----------------------------------------------------------\n");
+                throw new MojoExecutionException(
+                    "The root rpm build directory: " + rpmBuildContainerDirectory.getAbsolutePath() + " could not be deleted.");
+            }
+            
+            rpmBuildContainerDirectory.mkdirs();
+            tmpDirectory.mkdirs();
+            buildDirectory.mkdirs();
+            specsDirectory.mkdirs();
+            rpmsDirectory.mkdirs();
+            
+            Iterator<Project> projectIterator = projects.iterator();
+
+            MappingRoot model2LibrarySpecDescriptorMappingRoot = 
+                Pom2SpecTransform.createPomV400ToSpecV100MappingRoot();
+            
+            ResourceSet pomResourceSet  = 
+                ResourceSetInitializer.getInitializedPomV400ResourceSet();
+            
+            Map<String, Resource> artifactIdToPomResourceMap = 
+                new HashMap<String, Resource>();
+            
+            while(projectIterator.hasNext())
+            {
+                Project project          = projectIterator.next();
+                
+                String artifactId        = project.getArtifactId();
+                String groupId           = project.getGroupId();
+                String version           = project.getVersion();
+                                
+                String pomResourcePath = PomLoad.computePomResourcePath( 
+                    repositoryBaseDirectory.getAbsolutePath(), 
+                    groupId, 
+                    artifactId, 
+                    version );
+                
+                Resource pomResource = pomResourceSet.getResource(
+                    URI.createFileURI(pomResourcePath), true);
+                
+                Model model = 
+                    ( Model ) pomResource.getEObject(POM_PROJECT_FRAGMENT_PATH);
+                
+                if (model.getParent() != null)
+                {
+                    ArtifactIdToResourceMapBuilder.loadAncestors( 
+                        pomResourceSet, 
+                        pomResource, 
+                        artifactIdToPomResourceMap, 
+                        repositoryBaseDirectory );
+                    
+                    ProjectInitializer.initializeProject( 
+                        model, 
+                        artifactIdToPomResourceMap );
+                    
+                    
+                    EList<Dependency> dependencies = DependencyInitializer.initializeDependencies( 
+                        pomResource, 
+                        artifactIdToPomResourceMap );
+                    
+                    if ( dependencies != null )
+                    {
+                        DependencyFilter.filterRequiredDependencies( dependencies );                    
+                    }
+                }
+
+                LicensesType licensesType = model.getLicenses();
+                
+                boolean licenseInPom = ( licensesType != null );
+                
+                //If the pom does not have a license we don't rpm
+                if ( licenseInPom )
+                {
+                    EList<License> licenses   = licensesType.getLicense();
+                    License license           = licenses.get(0);
+                    String licenseName        = license.getName();
+                    
+                    LibrarySpecDescriptor librarySpecDescriptor = (LibrarySpecDescriptor)
+                    Pom2SpecTransform.transform(
+                    model, model2LibrarySpecDescriptorMappingRoot);
+                
+                    String artifactContainerDirectoryPath = 
+                        PomLoad.computePomContainerDirectoryPath( 
+                        repositoryBaseDirectory.getAbsolutePath(), 
+                        groupId, 
+                        artifactId, 
+                        version );
+                    
+                    librarySpecDescriptor.setLibraryDirectory( 
+                        artifactContainerDirectoryPath );
+                    
+                    //TODO Update when ecore2ecoreprocessor is fixed.
+                    librarySpecDescriptor.setLicense( licenseName );
+                    
+                    /*
+                     * Note that this also inserts values if the pom was missing values.
+                     * 
+                     * TODO - Check the pom description to make sure it contains a value.
+                     * I could just point users to the corresponding maven pom.
+                     * 
+                     * TODO Also use the description for description and a brief summary
+                     * generated summary for the summary
+                     */
+                    boolean librarySpecDescriptorValid = LibrarySpecValidator.validate(librarySpecDescriptor);
+                    
+                    if (librarySpecDescriptorValid)
+                    {
+                        LibrarySpecGenerator librarySpecGenerator = 
+                            new LibrarySpecGenerator();
+                        
+                        String result = 
+                            librarySpecGenerator.generate(librarySpecDescriptor);
+                        
+                        String specFileName = 
+                            model.getArtifactId() + 
+                            "-" + 
+                            model.getVersion() + 
+                            "." + 
+                            SPEC_RESOURCE_EXTENSION;
+                        
+                        File specFile = new File(specsDirectory.getAbsolutePath(), specFileName);
+                        specFile.delete();
+                        
+                        try {
+                            FileWriter fileWriter = new FileWriter(specFile);
+                            fileWriter.write(result);
+                            fileWriter.close();
+                        } catch (IOException e) {
+                             throw new MojoExecutionException("Could not write spec file to: "+ specFile.getAbsolutePath());
+                        }
+    
+                        getLog().info("-----------------------------------------------------------\n");
+                        getLog().info("Spec File Written to: " + specFile.getAbsolutePath());
+                        getLog().info("-----------------------------------------------------------\n");
+                        
+                        getLog().info("-----------------------------------------------------------\n");
+                        getLog().info("Starting rpmbuild.");
+                        getLog().info("-----------------------------------------------------------\n");
+    
+                        Commandline commandLine = new Commandline();
+                        StreamConsumer stdout = new StdoutConsumer( getLog() );
+                        StreamConsumer stderr = new StderrConsumer( getLog() );
+                        
+                        commandLine.setExecutable(RPMBUILD_COMMAND_STRING);
+                        
+                        commandLine.createArgument().setValue( "-bb");
+    
+                        commandLine.createArgument().setValue(RPMBUILD_ARGUMENT_TARGET_STRING);
+                        commandLine.createArgument().setValue(librarySpecDescriptor.getBuildArchitecture());
+                        
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_DEFINE_STRING );
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_TOP_DIR + rpmBuildContainerDirectory.getAbsolutePath() );
+                        
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_DEFINE_STRING );
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_TMP_DIR + tmpDirectory.getAbsolutePath() );
+                        
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_DEFINE_STRING );
+                        commandLine.createArgument().setValue( RPMBUILD_ARGUMENT_RPMS_DIR + rpmsDirectory.getAbsolutePath() );
+                        
+                        commandLine.createArgument().setValue( specFile.getAbsolutePath()  );
+                            
+                        try
+                        {
+                            int rpmBuildResult = CommandLineUtils.executeCommandLine( commandLine, stdout, stderr );
+                            if ( rpmBuildResult != 0 )
+                            {
+                                throw new MojoExecutionException( "RPM build execution returned: \'" + result + "\'." );
+                            }
+                        }
+                        catch ( CommandLineException e )
+                        {
+                            throw new MojoExecutionException( "Unable to build the RPM", e );
+                        }
+                    }
+                    
+                }
+                
+            }
+            
+            getLog().info("-----------------------------------------------------------\n");
+            getLog().info("RPM Packaging Complete");
+            getLog().info("-----------------------------------------------------------\n");
+
+        }
+   }
+    
+    //TODO Update these inner classes when switching to CommonsExec
+    /**
+     * Consumer to receive lines sent to stdout.  The lines are logged
+     * as info.
+     */
+    private class StdoutConsumer  implements StreamConsumer
+    {
+        /** Logger to receive the lines. */
+        private Log logger;
+        
+        /**
+         * Constructor.
+         * @param log The logger to receive the lines
+         */
+        public StdoutConsumer( Log log )
+        {
+            logger = log;
+        }
+        
+        /**
+         * Consume a line.
+         * @param string The line to consume
+         */
+        public void consumeLine( String string )
+        {
+            logger.info( string );
+        }
+    }
+
+    /**
+     * Consumer to receive lines sent to stderr.  The lines are logged
+     * as warnings.
+     */
+    private class StderrConsumer  implements StreamConsumer
+    {
+        /** Logger to receive the lines. */
+        private Log logger;
+        
+        /**
+         * Constructor.
+         * @param log The logger to receive the lines
+         */
+        public StderrConsumer( Log log )
+        {
+            logger = log;
+        }
+        
+        /**
+         * Consume a line.
+         * @param string The line to consume
+         */
+        public void consumeLine( String string )
+        {
+            logger.warn( string );
+        }
+    }
+
+    
+    
+    /*
+    public void createRPMDirectories() throws MojoExecutionException
+    {
+        File rpmBuildContainerDirectory = new File(
+            baseDirectory.getAbsolutePath(), 
+            rpmTopDirectoryPath);
+        
+        File tmpDirectory = new File(
+            rpmBuildContainerDirectory.getAbsolutePath(), rpmTmpDirectoryPath); 
+
+        File specsDirectory = new File(
+            rpmBuildContainerDirectory.getAbsolutePath(), rpmSpecsDirectoryPath); 
+
+        File rpmsDirectory = new File(
+            rpmBuildContainerDirectory.getAbsolutePath(), rpmRpmsDirectoryPath);
+        
+        try {
+            FileUtils.deleteDirectory(rpmBuildContainerDirectory);
+        } catch (IOException e) {
+            getLog().error("-----------------------------------------------------------\n");
+            getLog().error("The root rpm build directory: " + rpmBuildContainerDirectory.getAbsolutePath() + " could not be deleted.");
+            getLog().error("-----------------------------------------------------------\n");
+            throw new MojoExecutionException(
+                "The root rpm build directory: " + rpmBuildContainerDirectory.getAbsolutePath() + " could not be deleted.");
+        }
+        
+        rpmBuildContainerDirectory.mkdirs();
+        tmpDirectory.mkdirs();
+        specsDirectory.mkdirs();
+        rpmsDirectory.mkdirs();
+    }*/
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoConstants.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoConstants.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoConstants.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoConstants.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,49 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo;
+
+/*
+ * Copyright 2001-2005 The Apache Software 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.
+ */
+
+public interface RPMFactoryMojoConstants
+{
+    String MAVEN_REPOSITORY_METADATA_VERSION_1_FILE_NAME = "maven-metadata.xml";
+    String MAVEN_REPOSITORY_METADATA_VERSION_2_FILE_NAME = "maven-metadata-v200.xml";
+
+    String MAVEN_REPOSITORY_POM_EXTENSION                = "pom";
+    String XML_RESOURCE_EXTENSION                        = "xml";
+    String SPEC_RESOURCE_EXTENSION                       = "spec";
+    
+    String METADATA_FRAGMENT_PATH                        = "//@metadata";
+    String POM_PROJECT_FRAGMENT_PATH                     = "//@project";
+    String POM_DEPENDENCIES_FRAGMENT_PATH                = "//@project/@dependencies";
+    String POM_DEPENDENCY_MANAGEMENT_FRAGMENT_PATH       = "//@project/@dependencyManagement";
+    String POM_PARENT_FRAGMENT_PATH                      = "//@project/@parent";
+    
+    String DEPENDENCY_SCOPE_TEST                      = "test";
+    
+    String RPMBUILD_COMMAND_STRING          = "rpmbuild";
+    String RPMBUILD_ARGUMENT_TARGET_STRING  = "--target";
+    String RPMBUILD_ARGUMENT_DEFINE_STRING  = "--define";
+    String RPMBUILD_ARGUMENT_TOP_DIR        = "_topdir";
+    String RPMBUILD_ARGUMENT_TMP_DIR        = "_tmpdir";
+    String RPMBUILD_ARGUMENT_SOURCES_DIR    = "_sourcedir";
+    String RPMBUILD_ARGUMENT_BUILD_DIR      = "_builddir";
+    String RPMBUILD_ARGUMENT_RPMS_DIR       = "_rpmdir";
+    String RPMBUILD_ARGUMENT_SRPMS_DIR      = "_srcrpmdir";
+
+    
+    
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoHelper.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoHelper.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoHelper.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/RPMFactoryMojoHelper.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,160 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo;
+
+/*
+ * Copyright 2001-2005 The Apache Software 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.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.model.emf.metadata.v100.MetaData;
+import org.apache.maven.model.emf.metadata.v100.MetadataV100Package;
+import org.apache.maven.model.emf.metadata.v100.Versions;
+import org.apache.maven.model.emf.metadata.v100.util.MetadataV100ResourceFactoryImpl;
+import org.apache.maven.model.emf.metadata.v200.MetadataV200Package;
+import org.apache.maven.model.emf.metadata.v200.util.MetadataV200ResourceFactoryImpl;
+import org.apache.maven.plugin.MojoExecutionException;
+
+
+public class RPMFactoryMojoHelper 
+implements RPMFactoryMojoConstants
+{
+ 
+    
+    public static void generateRPM(MetaData metadata)
+    {
+        String artifactId      = metadata.getArtifactId();
+        String groupId         = metadata.getGroupId();
+        EList<String> versions = metadata.getVersioning().getVersions().getVersion();
+        
+        //Load the pom for the thing used to generate the spec file
+        
+        
+        
+        //generate the spec
+        
+        //run rpm on the spec
+        
+        //move the thing to the target directory
+        
+        
+    }
+    
+    
+/*    
+    public static void generateRecipes(
+        File recipeRootDirectory, 
+        Recipes recipes) 
+    throws MojoExecutionException
+    {
+        EList<RecipeGroup> checkGroups           = recipes.getRecipeGroups();
+        
+        Iterator<RecipeGroup> iterator           = checkGroups.iterator();
+
+        while(iterator.hasNext())
+        {
+            RecipeGroup recipeGroup   = ( RecipeGroup ) iterator.next();
+            
+            File recipeDirectory = new File(recipeRootDirectory, recipeGroup.getId());
+            
+            try
+            {
+                FileUtils.deleteDirectory( recipeDirectory );
+            }
+            catch ( IOException e )
+            {
+                e.printStackTrace();
+                throw new MojoExecutionException("TODO -Sexy Message");
+            }
+            
+            recipeDirectory.mkdirs();
+            
+            RecipeHTMLGenerator recipeHTMLGenerator 
+                                    = new RecipeHTMLGenerator();
+
+            EList<Recipe> recipeEList = recipeGroup.getRecipes();
+            Iterator<Recipe> recipeIterator = recipeEList.iterator();
+            Recipe recipe = null;
+            
+            while (recipeIterator.hasNext())
+            {
+                recipe = recipeIterator.next();
+                generateRecipe(
+                    recipe, 
+                    recipeHTMLGenerator, 
+                    recipeDirectory);
+            }
+        }
+    }
+*/
+    
+    /*
+     * TODO Consider catching NPE's from trying to access recipes that are non existant on the recipeMap
+     * This can occur when there's an invalid recipeReferenceId on a CheckItem.
+     * Also, I have to get the recipe both here and in the template.
+     * It would be sexier if I just had to get it in one place.
+     */
+  /*  
+    public static void generateRecipe(
+        Recipe recipe, 
+        RecipeHTMLGenerator recipeHTMLGenerator,
+        File recipeDirectory) throws MojoExecutionException 
+    {
+        String recipeString = recipeHTMLGenerator.generate( recipe );
+       
+        File recipeFile     = new File(recipeDirectory, recipe.getFileName());
+        
+        recipeFile.delete();
+        
+        try 
+        {
+            FileWriter fileWriter = new FileWriter(recipeFile);
+            fileWriter.write(recipeString);
+            fileWriter.close();
+        } catch (IOException e) 
+        {
+             throw new MojoExecutionException("Could not write recipe file to: "+ recipeFile.getAbsolutePath());
+        } 
+    }
+    
+    public static void generateTOC(
+        Recipes recipes) throws MojoExecutionException
+    {
+        TOCGenerator tocGenerator = new TOCGenerator();
+        String tocString = tocGenerator.generate(recipes);
+        File tocFile = new File(TOC_FILE_NAME);
+        tocFile.delete();
+        try 
+        {
+            FileWriter fileWriter = new FileWriter(tocFile);
+            fileWriter.write(tocString);
+            fileWriter.close();
+        } catch (IOException e) 
+        {
+             throw new MojoExecutionException("Could not write toc file to: " + tocFile.getAbsolutePath());
+        }    
+    }*/
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/AggregateMetadataBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/AggregateMetadataBuilder.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/AggregateMetadataBuilder.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/AggregateMetadataBuilder.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,52 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.build;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class AggregateMetadataBuilder {
+
+    /**
+     * Builds a RepositoryMetadata Version 2 Model from a list of Repository Metadata Version 1 models
+     *
+     * @param m Metadata
+     * @param metadataPath path
+     * @return RepositoryMetadata if the parameters represent one; null if not
+     * @todo should we just be using the path information, and loading it later when it is needed? (for reporting, etc)
+     */
+	
+	public static Resource createAggreatedMetadata(
+			List<Resource> metadataResources, 
+			ResourceSet resourceSet) throws FileSystemException
+	{
+		Iterator<Resource> metadataIterator = metadataResources.iterator();
+        while(metadataIterator.hasNext())
+		{
+            Resource metadataResource = metadataIterator.next();
+	    	EObject eObject = metadataResource.getEObject("//@metadata");
+	    	eObject.eSet(EcorePackage.eINSTANCE.getENamedElement_Name(), "project");
+            
+            
+
+	    	//I need an ecore2ecore processor thing here.
+	    	
+	    	
+	    	//Add the project object to the metadata root of the new 
+	    	//metadata resource.
+	    	
+	    	
+	    	
+//	    	resources.add(resource);
+		}
+		return null;//resources;
+	}
+
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/ArtifactIdToResourceMapBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/ArtifactIdToResourceMapBuilder.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/ArtifactIdToResourceMapBuilder.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/ArtifactIdToResourceMapBuilder.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,71 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.build;
+
+import java.io.File;
+import java.util.Map;
+
+import org.apache.maven.model.emf.pom.v400.Model;
+import org.apache.maven.model.emf.pom.v400.Parent;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.load.PomLoad;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class ArtifactIdToResourceMapBuilder implements RPMFactoryMojoConstants {
+	
+	/**
+	 * Load pom ancestors.
+	 * 
+	 * @param resourceSet the resource set used to load pom artifacts
+	 * @param artifactIdToPomResourceMap the artifact id to pom resource map
+	 * @param resource the pom resource
+	 * @param repositoryBaseDirectory the repository base directory
+	 * 
+	 * @return the map< string, resource>
+	 */
+	public static Map<String, Resource> loadAncestors(
+			ResourceSet resourceSet, 
+			Resource resource, 
+			Map<String, Resource> artifactIdToPomResourceMap,
+            File repositoryBaseDirectory) {
+		
+		Model model 	= (Model) resource.getEObject(POM_PROJECT_FRAGMENT_PATH);
+		Parent parent = model.getParent();
+		
+		if (parent != null)
+		{
+			String artifactId = parent.getArtifactId();
+			String groupId = parent.getGroupId();
+			String version = parent.getVersion();
+            
+            String parentResourcePath = 
+                PomLoad.computePomResourcePath( 
+                    repositoryBaseDirectory.getAbsolutePath(), 
+                    groupId, 
+                    artifactId, 
+                    version);
+			
+			resource = resourceSet.getResource(
+                URI.createFileURI(parentResourcePath), true); 
+
+			artifactIdToPomResourceMap.put(artifactId, resource);
+			
+			model = (Model) resource.getEObject(POM_PROJECT_FRAGMENT_PATH);
+			parent = model.getParent();
+
+			if (parent != null)
+			{
+				loadAncestors(
+						resourceSet, 
+						resource, 
+						artifactIdToPomResourceMap,
+                        repositoryBaseDirectory);
+			}
+			else 
+			{
+				return artifactIdToPomResourceMap;
+			}
+		}
+		return artifactIdToPomResourceMap;
+	}
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/MetadataListBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/MetadataListBuilder.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/MetadataListBuilder.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/MetadataListBuilder.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,47 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.build;
+
+import java.io.File;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelectInfo;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.VFS;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+
+public class MetadataListBuilder implements RPMFactoryMojoConstants {
+	
+    /**
+     * Returns an array of FileObject that have the name "maven-metadata.xml".  
+     *
+     * @param baseDir File pointing to the base directory.
+     * @return FileObject[] if maven-metadata.xml files are found. null otherwise.
+     * @throws MojoExecutionException 
+     */
+
+	public static FileObject[] discoverMetadata(File baseDirectory) throws MojoExecutionException
+	{
+		FileSelector fileSelector = new FileSelector()
+		{
+		    public boolean includeFile(FileSelectInfo fileInfo) throws Exception
+		    {
+		        FileObject fileObject = fileInfo.getFile();
+		        return fileObject.getName().getBaseName().contentEquals(MAVEN_REPOSITORY_METADATA_VERSION_1_FILE_NAME);
+		    }
+
+		    public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception
+		    {
+		        return true;
+		    }
+		};
+        
+		try
+        {
+            return VFS.getManager().resolveFile(baseDirectory.getAbsolutePath()).findFiles(fileSelector);
+        }
+        catch ( FileSystemException e )
+        {
+            throw new MojoExecutionException("An error ocurred while discovering metadata.  TODO - More info as these are debugged + look at the VFS code");        }
+	    }
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomFileListBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomFileListBuilder.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomFileListBuilder.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomFileListBuilder.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,47 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.build;
+
+import java.io.File;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelectInfo;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.VFS;
+import org.apache.maven.plugin.MojoExecutionException;
+
+public class PomFileListBuilder
+{
+    /**
+     * Returns an array of FileObject that have the name "*.pom".  
+     *
+     * @param baseDir File pointing to the base directory.
+     * @return FileObject[] if *.pom files are found. null otherwise.
+     * @throws MojoExecutionException 
+     */
+
+    public static FileObject[] discoverPomResources(File baseDirectory) throws MojoExecutionException
+    {
+        FileSelector fileSelector = new FileSelector()
+        {
+            public boolean includeFile(FileSelectInfo fileInfo) throws Exception
+            {
+                FileObject fileObject = fileInfo.getFile();
+                return fileObject.getName().getBaseName().endsWith(".pom");
+            }
+
+            public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception
+            {
+                return true;
+            }
+        };
+        
+        try
+        {
+            return VFS.getManager().resolveFile(baseDirectory.getAbsolutePath()).findFiles(fileSelector);
+        }
+        catch ( FileSystemException e )
+        {
+            throw new MojoExecutionException("An error ocurred while discovering metadata.  TODO - More info as these are debugged + look at the VFS code");        }
+        }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomName2ResourceMapBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomName2ResourceMapBuilder.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomName2ResourceMapBuilder.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/build/PomName2ResourceMapBuilder.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,63 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.build;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.maven.model.emf.metadata.v200.MetaData;
+import org.apache.maven.model.emf.metadata.v200.Project;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.apache.maven.plugins.rpm.factory.mojo.helpers.load.PomLoad;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class PomName2ResourceMapBuilder implements RPMFactoryMojoConstants {
+
+	public static Map<String, Resource> getPomName2ResourceMap(
+            File repositoryBaseDirectory,
+			MetaData metadataV2, 
+			ResourceSet resourceSet) throws MojoExecutionException
+	{
+		Map<String, Resource> pomName2ResourceMap   = new HashMap<String, Resource>();
+        
+        EList<Project> projectEList = metadataV2.getProjects();
+        
+        Iterator<Project> projectIterator    = projectEList.iterator();
+        
+        while (projectIterator.hasNext())
+        {
+            Project project = projectIterator.next();
+            
+            String artifactId   = project.getArtifactId();
+            String groupId      = project.getGroupId();
+            
+            EList versionEList = 
+                project.getVersioning().getVersions().getVersion();
+            
+            Iterator<String> versionIterator = versionEList.iterator();
+            
+            while (versionIterator.hasNext())
+            {
+                String version         = versionIterator.next();
+                String pomResourcePath = PomLoad.computePomResourcePath( 
+                    repositoryBaseDirectory.getAbsolutePath(), 
+                    groupId, 
+                    artifactId, 
+                    version );
+                
+                Resource pomResource      = 
+                    resourceSet.getResource( URI.createFileURI( 
+                    pomResourcePath ), true );
+                
+                String pomName = PomLoad.computePomName( artifactId, version );
+                
+                pomName2ResourceMap.put( pomName, pomResource );
+            }
+        }
+        return pomName2ResourceMap;
+	}
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/DependencyFilter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/DependencyFilter.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/DependencyFilter.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/DependencyFilter.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,27 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.filter;
+
+import java.util.Iterator;
+
+import org.apache.maven.model.emf.pom.v400.Dependency;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.eclipse.emf.common.util.EList;
+
+public class DependencyFilter implements RPMFactoryMojoConstants
+{
+    public static void filterRequiredDependencies(EList<Dependency> dependencies)
+    {
+        Iterator<Dependency> dependencyIterator = dependencies.iterator();
+        while (dependencyIterator.hasNext())
+        {
+            Dependency dependency   = (Dependency) dependencyIterator.next();
+            String scope            = dependency.getScope();
+            
+            if ( scope.equals(DEPENDENCY_SCOPE_TEST) )
+            {
+                dependencies.remove(dependency);
+            }
+        }       
+        
+    }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/MetadataV1ResourceFilter.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/MetadataV1ResourceFilter.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/MetadataV1ResourceFilter.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/filter/MetadataV1ResourceFilter.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,16 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.filter;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+
+public class MetadataV1ResourceFilter
+{
+    public static void buildArtifactProcessingList(EList<Resource> resources)
+    {
+        
+        
+        
+    }
+
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/DependencyInitializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/DependencyInitializer.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/DependencyInitializer.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/DependencyInitializer.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,187 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.maven.model.emf.pom.v400.DependenciesType;
+import org.apache.maven.model.emf.pom.v400.Dependency;
+import org.apache.maven.model.emf.pom.v400.DependencyManagement;
+import org.apache.maven.model.emf.pom.v400.Parent;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.resource.Resource;
+
+/**
+ * The POM DependencyInitializer.
+ */
+public class DependencyInitializer implements RPMFactoryMojoConstants
+{
+    /**
+     * Initialize the pom's dependencies when maven dependency management is used.
+     * 
+     * @param resource the resource
+     * @param artifactIdToPomResourceMap the artifact id to pom resource map
+     */
+    public static EList<Dependency> initializeDependencies(
+        Resource resource,
+        Map<String, Resource> artifactIdToPomResourceMap)
+    {
+        EList<Dependency> dependencies = null;
+        DependenciesType dependencyType   = 
+            (DependenciesType)resource.getEObject(POM_DEPENDENCIES_FRAGMENT_PATH);
+        
+        if (dependencyType != null)
+        {
+            dependencies          = dependencyType.getDependency();
+            
+            Iterator<Dependency> dependencyIterator = dependencies.iterator();
+
+            while(dependencyIterator.hasNext())
+            {
+                Dependency dependency   = (Dependency) dependencyIterator.next();
+                
+                String dependencyArtifactId = dependency.getArtifactId();
+                String dependencyScope      = dependency.getScope();
+                String dependencyVersion    = dependency.getVersion();
+
+                Parent parent     = (Parent) resource.getEObject(POM_PARENT_FRAGMENT_PATH);
+
+                if ((dependencyVersion == null) && (parent != null ))
+                {
+                    Dependency dependencyParent = findDependencyMatchInPomHiearchy(
+                        parent,
+                        artifactIdToPomResourceMap,
+                        dependencyArtifactId);
+                    
+                    if (dependencyParent != null)
+                    {
+                        dependency.setVersion(dependencyParent.getVersion());
+                        
+                        if (dependencyScope == null)
+                        {
+                            dependency.setScope(dependencyParent.getScope());
+                        }
+                    }
+                }
+            }
+        }
+        return dependencies;
+    }
+    
+    
+    
+    /**
+     * Find dependency match in pom hiearchy.
+     * 
+     * @param dependencyArtifactId the dependency artifact id
+     * @param artifactIdToPomResourceMap the artifact id to pom resource map
+     * @param parent the parent
+     * 
+     * @return the dependency
+     */
+    public static Dependency findDependencyMatchInPomHiearchy(
+        Parent parent,
+        Map<String, Resource> artifactIdToPomResourceMap,
+        String dependencyArtifactId)
+    {
+        Resource parentResource = artifactIdToPomResourceMap.get(
+            parent.getArtifactId());
+        
+        EList<Dependency> parentDependencies = 
+            computeParentDependencies( parentResource, artifactIdToPomResourceMap );
+        
+        Dependency dependency                = 
+            matchDependency(parentDependencies, dependencyArtifactId);
+        
+        if (dependency != null)
+        {
+            return dependency;
+        }
+        else
+        {
+            parent = (Parent) parentResource.getEObject( POM_PARENT_FRAGMENT_PATH );
+            
+            if ( parent != null)
+            {
+                return findDependencyMatchInPomHiearchy(
+                    parent, 
+                    artifactIdToPomResourceMap, 
+                    dependencyArtifactId);
+            }
+            else
+            {
+                return null;
+            }
+        }
+    }
+    
+    /**
+     * Finds a dependency management dependency that
+     * matches a artifactId of a child projects dependency.
+     * 
+     * This is used when the version of a dependency is specified
+     * on in a parent project's dependencyManagement section.
+     * 
+     * @param dependencyArtifactId the dependency artifact id
+     * @param dependencies the dependencies
+     * 
+     * @return the dependency
+     * 
+     * TODO Consider creating an index to speed this up.
+     * NOTES
+     * This way we would just use the dependencyArtifactId as a key
+     * We would thus have to create a dependencyArtifactId to Dependency
+     * map using all the dependencies in the dependency management section
+     * for the parent poms.  This could save time depending on the fraction
+     * of projects that use dependency management.
+     * 
+     * First do the the maven best practices plugins so that the ratio goes up
+     * then consider it.
+     */
+    public static Dependency matchDependency(
+        EList<Dependency> dependencies,
+        String dependencyArtifactId)
+    {
+        Iterator<Dependency> dependencyIterator = 
+            dependencies.iterator();
+        
+        boolean versionFound = false;
+        
+        while(dependencyIterator.hasNext() && !versionFound)
+        {
+            Dependency parentDependency = (Dependency) dependencyIterator.next();
+            if (parentDependency.getArtifactId() == dependencyArtifactId)
+            {
+                return parentDependency;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Compute parent dependencies.
+     * 
+     * @param parentResource the parent resource
+     * @param artifactIdToPomResourceMap the artifact id to pom resource map
+     * 
+     * @return the list< dependency> of dependencies
+     */
+    public static EList<Dependency> computeParentDependencies(
+        Resource parentResource, 
+        Map<String, Resource> artifactIdToPomResourceMap)
+    {
+        DependencyManagement dependencyManagement = 
+            (DependencyManagement) 
+            parentResource.getEObject(POM_DEPENDENCY_MANAGEMENT_FRAGMENT_PATH);
+
+        DependenciesType parentDependencyType     = 
+            (DependenciesType)
+            dependencyManagement.getDependencies();
+        
+        EList<Dependency> parentDependencies      = 
+            parentDependencyType.getDependency();
+        
+        return parentDependencies;
+    }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ProjectInitializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ProjectInitializer.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ProjectInitializer.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ProjectInitializer.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,129 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize;
+
+import java.util.Map;
+
+import org.apache.maven.model.emf.pom.v400.LicensesType;
+import org.apache.maven.model.emf.pom.v400.Model;
+import org.apache.maven.model.emf.pom.v400.Parent;
+import org.apache.maven.model.emf.pom.v400.PomV400Package;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+
+// TODO: Auto-generated Javadoc
+/**
+ * The Class ProjectInitializer.
+ */
+public class ProjectInitializer
+{
+    /**
+     * Initialize project.
+     * This looks for licenses, the project description, and the project url
+     * on the ancestor poms if they are not already contained in the target pom.
+     * 
+     * The youngest ancestor is searched first.  If the value is not found, then
+     * it's parent and so on.
+     * 
+     * @param model the model
+     * @param artifactIdToPomResourceMap the artifact id to pom resource map
+     * 
+     * TODO - If the project cannot be initialized properly, we could skip processing this project
+     * 
+     * TODO - Note that if the project does not have a url we could use the group id.
+     * 
+     * TODO - Analyze the maven repository and clean it up so that we don't have to hack
+     */
+    public static void initializeProject(
+        Model model, 
+        Map<String, Resource> artifactIdToPomResourceMap)
+    {
+        PomV400Package pomV400Package    = PomV400Package.eINSTANCE;
+        EAttribute descriptionEAttribute = pomV400Package.getModel_Description();
+        EAttribute urlEAttribute         = pomV400Package.getModel_Url();
+        EReference licensesEReference    = pomV400Package.getModel_Licenses();
+        
+        //EAttribute licenseName           = pomV400Package.getLicense_Name();
+        
+        String description = model.getDescription();
+        
+        if (description == null)
+        {
+            description = (String) lookupEStructuralFeatureValue( 
+                descriptionEAttribute, 
+                model, 
+                artifactIdToPomResourceMap );
+            
+            model.setDescription( description );
+        }
+        
+        String url         = model.getUrl();
+        
+        if (url == null)
+        {
+            url = (String) lookupEStructuralFeatureValue( 
+                urlEAttribute, 
+                model, 
+                artifactIdToPomResourceMap );
+            
+            if (url == null)
+            {
+                
+            }
+            //TODO note that we are setting url to groupid if it is not set
+            model.setUrl( model.getGroupId() );
+        }
+        
+        LicensesType licensesType = model.getLicenses();
+        
+        if (licensesType == null)
+        {
+            licensesType = (LicensesType) lookupEStructuralFeatureValue( 
+                licensesEReference, 
+                model, 
+                artifactIdToPomResourceMap );
+            
+            model.setLicenses( licensesType );
+        }
+    }
+    
+    /**
+     * Lookup E structural feature value.
+     * 
+     * @param model the model
+     * @param artifactIdToPomResourceMap the artifact id to pom resource map
+     * @param eAttribute the e attribute
+     * 
+     * @return the object
+     */
+    public static Object lookupEStructuralFeatureValue(
+        EStructuralFeature eAttribute, 
+        Model model,
+        Map<String, Resource> artifactIdToPomResourceMap)
+    {
+        Parent parent = model.getParent();
+        if (parent != null)
+        {
+            String artifactId = parent.getArtifactId();
+            
+            Resource parentResource = 
+                artifactIdToPomResourceMap.get( artifactId );
+            
+            Model parentModel  = ( Model ) parentResource.getEObject("//@project");
+            Object value = model.eGet( eAttribute );
+            if (value != null)
+            {
+                return value;
+            }
+            else if (model.getParent() != null)
+            {
+                return lookupEStructuralFeatureValue(
+                    eAttribute, 
+                    parentModel, 
+                    artifactIdToPomResourceMap);
+            }
+        }
+        return null;
+    }
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ResourceSetInitializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ResourceSetInitializer.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ResourceSetInitializer.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/initialize/ResourceSetInitializer.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,67 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.initialize;
+
+import org.apache.maven.model.emf.metadata.v100.MetadataV100Package;
+import org.apache.maven.model.emf.metadata.v100.util.MetadataOptionalNamespaceResourceFactoryImpl;
+import org.apache.maven.model.emf.metadata.v200.MetadataV200Package;
+import org.apache.maven.model.emf.metadata.v200.util.MetadataV200ResourceFactoryImpl;
+import org.apache.maven.model.emf.pom.v400.PomV400Package;
+import org.apache.maven.model.emf.pom.v400.util.PomV400OptionalNamespaceResourceFactory;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+
+public class ResourceSetInitializer implements RPMFactoryMojoConstants {
+	
+	public static ResourceSet getInitializedMetadataV100ResourceSet()
+	{
+		ResourceSet resourceSet = new ResourceSetImpl();
+
+		resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
+		(XML_RESOURCE_EXTENSION, 
+		 new MetadataOptionalNamespaceResourceFactoryImpl());
+		
+		resourceSet.getPackageRegistry().put
+		(		
+            MetadataV100Package.eNS_URI, 
+            MetadataV100Package.eINSTANCE
+		);
+        return resourceSet;
+	}
+    
+    public static ResourceSet getInitializedMetadataV200ResourceSet()
+    {
+        ResourceSet resourceSet = new ResourceSetImpl();
+
+
+        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
+        (XML_RESOURCE_EXTENSION, 
+         new MetadataV200ResourceFactoryImpl());
+        
+        resourceSet.getPackageRegistry().put
+        (       
+            MetadataV200Package.eNS_URI, 
+            MetadataV200Package.eINSTANCE
+        );
+        
+        return resourceSet;
+    }
+
+    public static ResourceSet getInitializedPomV400ResourceSet()
+    {
+        ResourceSet resourceSet = new ResourceSetImpl();
+
+
+        resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put
+        (MAVEN_REPOSITORY_POM_EXTENSION, 
+         new PomV400OptionalNamespaceResourceFactory());
+        
+        resourceSet.getPackageRegistry().put
+        (       
+            PomV400Package.eNS_URI, 
+            PomV400Package.eINSTANCE
+        );
+        return resourceSet;
+    }
+
+
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/MetadataResourceLoad.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/MetadataResourceLoad.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/MetadataResourceLoad.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/MetadataResourceLoad.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,41 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.load;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class MetadataResourceLoad {
+
+	public static List<Resource> getMetadataResources(
+			FileObject[] metadataFiles, 
+			ResourceSet resourceSet) throws MojoExecutionException
+	{
+		List<Resource> resources   = new ArrayList<Resource>();
+        
+		for (int i = 0; i<metadataFiles.length; i++)
+		{
+			FileObject fileObject = metadataFiles[i];
+			String fileObjectPath = null;
+            try
+            {
+                fileObjectPath = fileObject.getURL().getFile();
+            }
+            catch ( FileSystemException e )
+            {
+                throw new MojoExecutionException("Stuff Happened here + TODO More Info");
+            }
+			
+	    	Resource resource = resourceSet.getResource(
+	    			URI.createFileURI(fileObjectPath), true);
+	    	
+	    	resources.add(resource);
+		}
+		return resources;
+	}
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomLoad.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomLoad.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomLoad.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomLoad.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,70 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.load;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class PomLoad implements  RPMFactoryMojoConstants
+{
+    //TODO Use a generic method instead of this.
+    public Resource load(
+        String pomResourcePath, 
+        ResourceSet resourceSet)
+    {
+        Resource resource = 
+            resourceSet.getResource(
+                URI.createFileURI(pomResourcePath), true);
+        return resource;
+    }
+    
+    public static String computePomResourcePath(
+        String repositoryBaseDirectoryPath,
+        String groupId, 
+        String artifactId, 
+        String version)
+    {
+        return 
+        computePomContainerDirectoryPath(
+                repositoryBaseDirectoryPath, 
+                groupId, 
+                artifactId, 
+                version) +
+            "/" + 
+            computePomName(artifactId, version); 
+ 
+    }
+    
+    public static String computePomContainerDirectoryPath(
+        String repositoryBaseDirectoryPath,
+        String groupId, 
+        String artifactId,
+        String version)
+    {
+        String groupIdSegment  = StringUtils.replace( groupId, ".", "/" );
+
+        return
+            repositoryBaseDirectoryPath + 
+            "/" + 
+            groupIdSegment + 
+            "/" + 
+            artifactId +
+            "/" +
+            version;
+    }
+    
+    public static String computePomName(String artifactId, String version)
+    {
+        return 
+            artifactId + 
+            "-" 
+            + 
+            version 
+            + 
+            "." 
+            + 
+            MAVEN_REPOSITORY_POM_EXTENSION;
+    }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomResourceLoad.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomResourceLoad.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomResourceLoad.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/load/PomResourceLoad.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,43 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.load;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+
+public class PomResourceLoad {
+
+	public static List<Resource> loadPomResources(
+			FileObject[] pomFiles, 
+			ResourceSet resourceSet) throws MojoExecutionException
+	{
+		List<Resource> resources   = new ArrayList<Resource>();
+        
+		for (int i = 0; i<pomFiles.length; i++)
+		{
+			FileObject fileObject = pomFiles[i];
+			String fileObjectPath = null;
+            try
+            {
+                fileObjectPath = fileObject.getURL().getFile();
+            }
+            catch ( FileSystemException e )
+            {
+                throw new MojoExecutionException("Stuff Happened here + TODO More Info");
+            }
+			
+	    	Resource resource = resourceSet.getResource(
+	    			URI.createFileURI(fileObjectPath), true);
+            
+            //See whether we want this pom first.
+	    	
+	    	resources.add(resource);
+		}
+		return resources;
+	}
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/MetadataV1ToMetadataV2Transform.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/MetadataV1ToMetadataV2Transform.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/MetadataV1ToMetadataV2Transform.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/MetadataV1ToMetadataV2Transform.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,166 @@
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.transform;
+
+import org.apache.tuscany.model.emf.ecore2ecore.Ecore2EcoreFactory;
+import org.apache.tuscany.model.emf.ecore2ecore.Mapping;
+import org.apache.tuscany.model.emf.ecore2ecore.MappingRoot;
+import org.apache.tuscany.model.emf.processor.ecore2ecore.impl.Ecore2EcoreProcessor;
+import org.apache.maven.model.emf.metadata.v100.MetaData;
+import org.apache.maven.model.emf.metadata.v100.MetadataV100Package;
+import org.apache.maven.model.emf.metadata.v200.MetadataV200Package;
+import org.apache.maven.model.emf.metadata.v200.Project;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.rpm.factory.mojo.RPMFactoryMojoConstants;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+public class MetadataV1ToMetadataV2Transform 
+implements RPMFactoryMojoConstants {
+    
+    private static Ecore2EcoreFactory ecore2ecoreFactory = 
+        Ecore2EcoreFactory.eINSTANCE;
+    
+    private static MetadataV100Package metadataPackageVersion1 = 
+        MetadataV100Package.eINSTANCE;
+
+    private static MetadataV200Package metadataPackageVersion2 = 
+        MetadataV200Package.eINSTANCE;
+    
+    private static MappingRoot metadataV1ToMetadataV2MappingRoot = null;
+
+    /**
+     * Returns an EObject that is a Project instance.  
+     *
+     * @param metadata File pointing to the base directory.
+     * @param metadata File pointing to the base directory.
+     * @return EObject Project EObject that corresponds to the metadata argument
+     */
+
+	public static EObject transform(EObject metadata, MappingRoot mappingRoot)
+	{
+        EObject project = 
+            Ecore2EcoreProcessor.execute(
+                metadata, 
+                mappingRoot);
+        return project;
+    }
+
+    
+	public static MappingRoot createMetadataV1ToMetadataV2MappingRoot()
+    {
+        MappingRoot metadataV1ToMetadataV2MappingRoot = 
+            ecore2ecoreFactory.createMappingRoot();
+
+        EClass metadataV1EClass   = metadataPackageVersion1.getMetaData();
+        EClass versioningV1EClass = metadataPackageVersion1.getVersioning();
+        EClass versionsV1EClass   = metadataPackageVersion1.getVersions();
+        
+        Mapping metadataV1ToProjectV2Mapping        = 
+            createMetadataV1ToProjectV2Mapping();
+        Mapping versioningV1ToVersioningV2Mapping   = 
+            createVersioningV1ToVersioningV2Mapping();
+        Mapping versionsV1ToVersionsV2Mapping       = 
+            createVersionsV1ToVersionsV2Mapping();
+        
+        metadataV1ToMetadataV2MappingRoot.
+        getEClass2MappingMap().
+        put( metadataV1EClass, metadataV1ToProjectV2Mapping );
+        
+        metadataV1ToMetadataV2MappingRoot.
+        getEClass2MappingMap().
+        put( versioningV1EClass, versioningV1ToVersioningV2Mapping );
+        
+        metadataV1ToMetadataV2MappingRoot.
+        getEClass2MappingMap().
+        put( versionsV1EClass, versionsV1ToVersionsV2Mapping );
+
+        return metadataV1ToMetadataV2MappingRoot;
+    }
+    
+    public static Mapping createMetadataV1ToProjectV2Mapping()
+    {
+        Mapping metadataV1ToProjectV2Mapping          =
+            ecore2ecoreFactory.createMapping();
+
+        EClass projectEClass            = metadataPackageVersion2.getProject();
+        
+        EAttribute metadataArtifactId   = metadataPackageVersion1.getMetaData_ArtifactId();
+        EAttribute projectArtifactId    = metadataPackageVersion2.getProject_ArtifactId();
+        
+        EAttribute metadataGroupId      = metadataPackageVersion1.getMetaData_GroupId();
+        EAttribute projectGroupId       = metadataPackageVersion2.getProject_GroupId();
+        
+        EAttribute metadataVersion      = metadataPackageVersion1.getMetaData_Version();
+        EAttribute projectVersion       = metadataPackageVersion2.getProject_Version();
+        
+        EReference metadataVersioning   = metadataPackageVersion1.getMetaData_Versioning();
+        EReference projectVersioning    = metadataPackageVersion2.getProject_Versioning();
+        
+        metadataV1ToProjectV2Mapping.setTargetEClass( projectEClass );
+
+        
+        metadataV1ToProjectV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(metadataArtifactId, projectArtifactId);
+        
+        metadataV1ToProjectV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(metadataGroupId, projectGroupId);
+        
+        metadataV1ToProjectV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(metadataVersion, projectVersion);
+
+        metadataV1ToProjectV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(metadataVersioning, projectVersioning);
+
+        return metadataV1ToProjectV2Mapping;
+    }
+    
+    public static Mapping createVersioningV1ToVersioningV2Mapping()
+    {
+        EClass versioningV2EClass          = metadataPackageVersion2.getVersioning();
+        
+        EAttribute versioningV1LastUpdated = metadataPackageVersion1.getVersioning_LastUpdated();
+        EAttribute versioningV2LastUpdated = metadataPackageVersion2.getVersioning_LastUpdated();
+        
+        EReference versioningV1Versions    = metadataPackageVersion1.getVersioning_Versions();
+        EReference versioningV2Versions    = metadataPackageVersion2.getVersioning_Versions();
+        
+        Mapping versioningV1ToVersioningV2Mapping =
+            ecore2ecoreFactory.createMapping();
+        
+        versioningV1ToVersioningV2Mapping.setTargetEClass( versioningV2EClass );
+
+        versioningV1ToVersioningV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(versioningV1LastUpdated, versioningV2LastUpdated);
+        
+        versioningV1ToVersioningV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(versioningV1Versions, versioningV2Versions);
+        
+        return versioningV1ToVersioningV2Mapping;   
+    }
+    
+    public static Mapping createVersionsV1ToVersionsV2Mapping()
+    {
+        EClass versionsV2EClass          = metadataPackageVersion2.getVersions();
+
+        EAttribute versionsV1Version = metadataPackageVersion1.getVersions_Version();
+        EAttribute versionsV2Version = metadataPackageVersion2.getVersions_Version();
+
+        Mapping versionsV1ToVersionsV2Mapping =
+            ecore2ecoreFactory.createMapping();
+        
+        versionsV1ToVersionsV2Mapping.setTargetEClass( versionsV2EClass );
+
+        versionsV1ToVersionsV2Mapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(versionsV1Version, versionsV2Version);
+        
+        return versionsV1ToVersionsV2Mapping;
+    }
+}
\ No newline at end of file

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/Pom2SpecTransform.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/Pom2SpecTransform.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/Pom2SpecTransform.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/transform/Pom2SpecTransform.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,102 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.transform;
+
+import org.apache.maven.model.emf.pom.v400.PomV400Package;
+import org.apache.maven.rpm.factory.model.spec.v100.SpecV100Package;
+import org.apache.tuscany.model.emf.ecore2ecore.Ecore2EcoreFactory;
+import org.apache.tuscany.model.emf.ecore2ecore.Mapping;
+import org.apache.tuscany.model.emf.ecore2ecore.MappingRoot;
+import org.apache.tuscany.model.emf.processor.ecore2ecore.impl.Ecore2EcoreProcessor;
+import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+
+public class Pom2SpecTransform
+{
+    private static Ecore2EcoreFactory ecore2ecoreFactory = 
+        Ecore2EcoreFactory.eINSTANCE;
+    
+    private static SpecV100Package specV100Package = 
+        SpecV100Package.eINSTANCE;
+    
+    private static PomV400Package pomV400Package = 
+        PomV400Package.eINSTANCE;
+    
+    public static EObject transform(EObject project, MappingRoot mappingRoot)
+    {
+        EObject library = 
+            Ecore2EcoreProcessor.execute(
+                project, 
+                mappingRoot);
+        return library;
+    }
+
+    public static MappingRoot createPomV400ToSpecV100MappingRoot()
+    {
+        MappingRoot pomV400ToSpecV100MappingRoot = 
+            ecore2ecoreFactory.createMappingRoot();
+        
+        EClass projectEClass = pomV400Package.getModel();
+
+        Mapping projectToLibrarySpecDescriptorMapping = 
+            createProjectToLibrarySpecDescriptorMapping();
+        
+        pomV400ToSpecV100MappingRoot.
+        
+        getEClass2MappingMap().put( 
+            projectEClass, 
+            projectToLibrarySpecDescriptorMapping );
+        
+        return pomV400ToSpecV100MappingRoot;
+    }
+    
+    
+    public static Mapping createProjectToLibrarySpecDescriptorMapping()
+    {
+        Mapping projectToLibrarySpecDescriptorMapping          =
+            ecore2ecoreFactory.createMapping();
+        
+        EClass librarySpecDescriptorEClass = specV100Package.getLibrarySpecDescriptor();
+        
+        EAttribute projectArtifactId  = pomV400Package.getModel_ArtifactId(); 
+        EAttribute libraryName        = specV100Package.getAbstractSpecDescriptor_Name();
+        
+        EAttribute projectVersion     = pomV400Package.getModel_Version();
+        EAttribute libraryVersion     = specV100Package.getAbstractSpecDescriptor_Version();
+       
+        EAttribute projectDescription = pomV400Package.getModel_Description();
+        EAttribute libraryDescription = specV100Package.getAbstractSpecDescriptor_Description();
+        
+        EAttribute projectUrl = pomV400Package.getModel_Url();
+        EAttribute libraryUrl = specV100Package.getAbstractSpecDescriptor_Url();
+
+        
+        EReference projectDependencies= pomV400Package.getModel_Dependencies();
+        EReference libraryDependencies= specV100Package.getLibrarySpecDescriptor_RequiresDependencies();
+        
+        projectToLibrarySpecDescriptorMapping.setTargetEClass( librarySpecDescriptorEClass );
+        
+        projectToLibrarySpecDescriptorMapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(projectArtifactId,  libraryName);
+        
+        projectToLibrarySpecDescriptorMapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(projectVersion,  libraryVersion);
+
+        projectToLibrarySpecDescriptorMapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(projectDescription,  libraryDescription);
+
+        projectToLibrarySpecDescriptorMapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(projectUrl,  libraryUrl);
+
+        projectToLibrarySpecDescriptorMapping.
+        getEStructuralFeature2EStructuralFeatureMap().
+        put(projectDependencies,  libraryDependencies);
+
+        return projectToLibrarySpecDescriptorMapping;
+     }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/validate/LibrarySpecValidator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/validate/LibrarySpecValidator.java?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/validate/LibrarySpecValidator.java (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/java/org/apache/maven/plugins/rpm/factory/mojo/helpers/validate/LibrarySpecValidator.java Thu Mar 15 14:50:22 2007
@@ -0,0 +1,43 @@
+
+package org.apache.maven.plugins.rpm.factory.mojo.helpers.validate;
+
+import org.apache.maven.rpm.factory.model.spec.v100.LibrarySpecDescriptor;
+
+public class LibrarySpecValidator
+{
+    public static boolean validate(LibrarySpecDescriptor librarySpecDescriptor)
+    {
+        String version = librarySpecDescriptor.getVersion();
+        if (version.contains( "-" ))
+        {
+            return false;
+        }
+        
+        if (
+            librarySpecDescriptor.getSummary() == null || 
+            librarySpecDescriptor.getLicense() == null ||
+            librarySpecDescriptor.getUrl() == null)
+        {
+            System.out.println(librarySpecDescriptor.getName());
+            System.out.println(librarySpecDescriptor.getVersion());
+            System.out.println(librarySpecDescriptor.getLicense());
+            System.out.println(librarySpecDescriptor.getSummary());
+            System.out.println(librarySpecDescriptor.getUrl());
+
+            return false;
+        }
+        else
+        {
+            System.out.println(librarySpecDescriptor.getName());
+            System.out.println(librarySpecDescriptor.getVersion());
+            System.out.println(librarySpecDescriptor.getLicense());
+            System.out.println(librarySpecDescriptor.getSummary());
+
+            System.out.println("===================================================\n");
+            System.out.println("Return TRUE");
+            System.out.println("===================================================\n");
+            
+            return true;
+        }
+    }
+}

Added: directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/resources/META-INF/plexus/component.xml
URL: http://svn.apache.org/viewvc/directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/resources/META-INF/plexus/component.xml?view=auto&rev=518765
==============================================================================
--- directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/resources/META-INF/plexus/component.xml (added)
+++ directory/sandbox/oersoy/rpm.factory.parent/rpm.factory.mojo/src/main/resources/META-INF/plexus/component.xml Thu Mar 15 14:50:22 2007
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component-set>
+  <components>
+    <component>
+      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
+      <role-hint>rpm.factory</role-hint>
+      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
+      <configuration>
+        <phases>
+          <generate>org.apache.maven:rpm.factory.mojo:generate</generate>
+          <package>org.codehaus.plexus:plexus-maven-plugin:app</package>
+          <install>org.apache.maven.plugins:maven-install-plugin:install</install>
+          <deploy>org.apache.maven.plugins:maven-deploy-plugin:deploy</deploy>
+        </phases>
+      </configuration>
+    </component>
+  </components>
+</component-set>
\ No newline at end of file



Mime
View raw message