Package org.codehaus.plexus.archiver.jar

Examples of org.codehaus.plexus.archiver.jar.Manifest


     */
    public Manifest getManifest( MavenProject project, ManifestConfiguration config )
        throws ManifestException, DependencyResolutionRequiredException
    {
        // Added basic entries
        Manifest m = new Manifest();
        Manifest.Attribute buildAttr = new Manifest.Attribute( "Built-By", System.getProperty( "user.name" ) );
        m.addConfiguredAttribute( buildAttr );
        Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
        m.addConfiguredAttribute( createdAttr );

/* TODO: rethink this, it wasn't working
        Artifact projectArtifact = project.getArtifact();

        if ( projectArtifact.isSnapshot() )
        {
            Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" +
                project.getSnapshotDeploymentBuildNumber() );
            m.addConfiguredAttribute( buildNumberAttr );
        }

*/
        if ( config.getPackageName() != null )
        {
            Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
            m.addConfiguredAttribute( packageAttr );
        }

        Manifest.Attribute buildJdkAttr = new Manifest.Attribute( "Build-Jdk", System.getProperty( "java.version" ) );
        m.addConfiguredAttribute( buildJdkAttr );

        if ( config.isAddClasspath() )
        {
            StringBuffer classpath = new StringBuffer();
            List artifacts = project.getRuntimeClasspathElements();
            String classpathPrefix = config.getClasspathPrefix();

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                File f = new File( (String) iter.next() );
                if ( f.isFile() )
                {
                    if ( classpath.length() > 0 )
                    {
                        classpath.append( " " );
                    }

                    classpath.append( classpathPrefix );
                    classpath.append( f.getName() );
                }
            }

            if ( classpath.length() > 0 )
            {
                Manifest.Attribute classpathAttr = new Manifest.Attribute( "Class-Path", classpath.toString() );
                m.addConfiguredAttribute( classpathAttr );
            }
        }

        // Added supplementary entries
        Manifest.Attribute extensionNameAttr = new Manifest.Attribute( "Extension-Name", project.getArtifactId() );
        m.addConfiguredAttribute( extensionNameAttr );

        if ( project.getDescription() != null )
        {
            Manifest.Attribute specificationTitleAttr = new Manifest.Attribute( "Specification-Title",
                                                                                project.getDescription() );
            m.addConfiguredAttribute( specificationTitleAttr );
        }

        if ( project.getOrganization() != null )
        {
            Manifest.Attribute specificationVendor = new Manifest.Attribute( "Specification-Vendor",
                                                                             project.getOrganization().getName() );
            m.addConfiguredAttribute( specificationVendor );
            Manifest.Attribute implementationVendorAttr = new Manifest.Attribute( "Implementation-Vendor",
                                                                                  project.getOrganization().getName() );
            m.addConfiguredAttribute( implementationVendorAttr );
        }

        Manifest.Attribute implementationTitleAttr = new Manifest.Attribute( "Implementation-Title",
                                                                             project.getArtifactId() );
        m.addConfiguredAttribute( implementationTitleAttr );
        Manifest.Attribute implementationVersionAttr = new Manifest.Attribute( "Implementation-Version",
                                                                               project.getVersion() );
        m.addConfiguredAttribute( implementationVersionAttr );

        String mainClass = config.getMainClass();
        if ( mainClass != null && !"".equals( mainClass ) )
        {
            Manifest.Attribute mainClassAttr = new Manifest.Attribute( "Main-Class", mainClass );
            m.addConfiguredAttribute( mainClassAttr );
        }

        // Added extensions
        if ( config.isAddExtensions() )
        {
            StringBuffer extensionsList = new StringBuffer();
            Set artifacts = project.getArtifacts();

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                Artifact artifact = (Artifact) iter.next();
                // TODO: type of ejb should be added too?
                if ( "jar".equals( artifact.getType() ) )
                {
                    if ( extensionsList.length() > 0 )
                    {
                        extensionsList.append( " " );
                    }
                    extensionsList.append( artifact.getArtifactId() );
                }
            }

            if ( extensionsList.length() > 0 )
            {
                Manifest.Attribute extensionsListAttr = new Manifest.Attribute( "Extension-List",
                                                                                extensionsList.toString() );
                m.addConfiguredAttribute( extensionsListAttr );
            }

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                Artifact artifact = (Artifact) iter.next();
                if ( "jar".equals( artifact.getType() ) )
                {
                    Manifest.Attribute archExtNameAttr = new Manifest.Attribute(
                        artifact.getArtifactId() + "-Extension-Name", artifact.getArtifactId() );
                    m.addConfiguredAttribute( archExtNameAttr );
                    String name = artifact.getArtifactId() + "-Implementation-Version";
                    Manifest.Attribute archImplVersionAttr = new Manifest.Attribute( name, artifact.getVersion() );
                    m.addConfiguredAttribute( archImplVersionAttr );

                    if ( artifact.getRepository() != null )
                    {
                        // TODO: is this correct
                        name = artifact.getArtifactId() + "-Implementation-URL";
                        String url = artifact.getRepository().getUrl() + "/" + artifact.toString();
                        Manifest.Attribute archImplUrlAttr = new Manifest.Attribute( name, url );
                        m.addConfiguredAttribute( archImplUrlAttr );
                    }
                }
            }
        }

View Full Code Here


        if ( manifestFile != null )
        {
            archiver.setManifest( manifestFile );
        }

        Manifest manifest = getManifest( workingProject, archiveConfiguration.getManifest() );

        // any custom manifest entries in the archive configuration manifest?
        if ( !archiveConfiguration.isManifestEntriesEmpty() )
        {
            Map entries = archiveConfiguration.getManifestEntries();
            Set keys = entries.keySet();
            for ( Iterator iter = keys.iterator(); iter.hasNext(); )
            {
                String key = (String) iter.next();
                String value = (String) entries.get( key );
                Manifest.Attribute attr = new Manifest.Attribute( key, value );
                manifest.addConfiguredAttribute( attr );
            }
        }

        // any custom manifest sections in the archive configuration manifest?
        if ( !archiveConfiguration.isManifestSectionsEmpty() )
        {
          List sections = archiveConfiguration.getManifestSections();
          for ( Iterator iter = sections.iterator(); iter.hasNext(); )
          {
            ManifestSection section = (ManifestSection) iter.next();
            Manifest.Section theSection = new Manifest.Section();
            theSection.setName( section.getName() );
           
            if( !section.isManifestEntriesEmpty() ) {
              Map entries = section.getManifestEntries();
              Set keys = entries.keySet();
              for ( Iterator it = keys.iterator(); it.hasNext(); )
              {
                        String key = (String) it.next();
                        String value = (String) entries.get( key );
                        Manifest.Attribute attr = new Manifest.Attribute( key, value );
                theSection.addConfiguredAttribute( attr );
              }
            }
           
            manifest.addConfiguredSection( theSection );
          }
        }
       
        // Configure the jar
        archiver.addConfiguredManifest( manifest );
View Full Code Here

            file = FileUtils.createTempFile("cxf-codegen", ".jar");

            JarArchiver jar = new JarArchiver();
            jar.setDestFile(file.getAbsoluteFile());

            Manifest manifest = new Manifest();
            Attribute attr = new Attribute();
            attr.setName("Class-Path");
            StringBuilder b = new StringBuilder(8000);
            for (URI cp : classPath) {
                b.append(cp.toURL().toExternalForm()).append(' ');
            }
            attr.setValue(b.toString());
            manifest.getMainSection().addConfiguredAttribute(attr);

            attr = new Attribute();
            attr.setName("Main-Class");
            attr.setValue(mainClassName);
            manifest.getMainSection().addConfiguredAttribute(attr);

            jar.addConfiguredManifest(manifest);
            jar.createArchive();

            cmd.createArg().setValue("-jar");
View Full Code Here

    }

    public Manifest getManifest( MavenSession session, MavenProject project, MavenArchiveConfiguration config )
        throws ManifestException, DependencyResolutionRequiredException
    {
        final Manifest manifest = super.getManifest( session, project, config );
        if ( config.getManifest().isAddClasspath() )
        {
            String earManifestClassPathEntry = generateClassPathEntry( config.getManifest().getClasspathPrefix() );
            // Class-path can be customized. Let's make sure we don't overwrite this
            // with our custom change!
            final String userSuppliedClassPathEntry = getUserSuppliedClassPathEntry( config );
            if ( userSuppliedClassPathEntry != null )
            {
                earManifestClassPathEntry = userSuppliedClassPathEntry + " " + earManifestClassPathEntry;
            }

            // Overwrite the existing one, if any
            final Manifest.Attribute classPathAttr = manifest.getMainSection().getAttribute( CLASS_PATH_KEY );
            if ( classPathAttr != null )
            {
                classPathAttr.setValue( earManifestClassPathEntry );
            }
            else
            {
                final Manifest.Attribute attr = new Manifest.Attribute( CLASS_PATH_KEY, earManifestClassPathEntry );
                manifest.addConfiguredAttribute( attr );
            }
        }
        return manifest;
    }
View Full Code Here

            {
                getLog().debug( "This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." );
            }

            // Read the manifest from disk
            Manifest mf = new Manifest( new FileReader( manifestFile ) );
            Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" );
            List<String> classPathElements = new ArrayList<String>();

            if ( classPath != null )
            {
                classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) );
            }
            else
            {
                classPath = new Attribute( "Class-Path", "" );
            }

            // Modify the classpath entries in the manifest
            for ( EarModule o : getModules() )
            {
                if ( o instanceof JarModule )
                {
                    JarModule jm = (JarModule) o;

                    if ( module.getLibDir() != null )
                    {
                        //MEAR-189:
                        //We use the original name, cause in case of fileNameMapping to no-version/full
                        //we coulnd not not delete it and it will end up in the resulting EAR and the WAR
                        //will not be cleaned up.
                        File artifact =
                            new File( new File( workDirectory, module.getLibDir() ), jm.getOriginalBundleFileName() );

                        if ( artifact.exists() )
                        {
                            getLog().debug( " -> Artifact to delete: " + artifact );
                            if ( !artifact.delete() )
                            {
                                getLog().error( "Could not delete '" + artifact + "'" );
                            }
                        }
                    }

                    if ( classPathElements.contains( jm.getBundleFileName() ) )
                    {
                        classPathElements.set( classPathElements.indexOf( jm.getBundleFileName() ), jm.getUri() );
                    }
                    else
                    {
                        classPathElements.add( jm.getUri() );
                    }
                }
            }
            classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );
            mf.getMainSection().addConfiguredAttribute( classPath );

            // Write the manifest to disk
            PrintWriter pw = new PrintWriter( manifestFile );
            mf.write( pw );
            pw.close();

            if ( original.isFile() )
            {
                // Pack up the archive again from the work directory
View Full Code Here

    }

    public Manifest getManifest( MavenSession session, MavenProject project, MavenArchiveConfiguration config )
        throws ManifestException, DependencyResolutionRequiredException
    {
        final Manifest manifest = super.getManifest( session, project, config );
        if ( config.getManifest().isAddClasspath() )
        {
            String earManifestClassPathEntry = generateClassPathEntry( config.getManifest().getClasspathPrefix() );
            // Class-path can be customized. Let's make sure we don't overwrite this
            // with our custom change!
            final String userSuppliedClassPathEntry = getUserSuppliedClassPathEntry( config );
            if ( userSuppliedClassPathEntry != null )
            {
                earManifestClassPathEntry = userSuppliedClassPathEntry + " " + earManifestClassPathEntry;
            }

            // Overwrite the existing one, if any
            final Manifest.Attribute classPathAttr = manifest.getMainSection().getAttribute( CLASS_PATH_KEY );
            if ( classPathAttr != null )
            {
                classPathAttr.setValue( earManifestClassPathEntry );
            }
            else
            {
                final Manifest.Attribute attr = new Manifest.Attribute( CLASS_PATH_KEY, earManifestClassPathEntry );
                manifest.addConfiguredAttribute( attr );
            }
        }
        return manifest;
    }
View Full Code Here

                getLog().debug(
                    "This project did not have a META-INF/MANIFEST.MF file before, so a new file was created." );
            }

            // Read the manifest from disk
            Manifest mf = new Manifest( new FileReader( manifestFile ) );
            Attribute classPath = mf.getMainSection().getAttribute( "Class-Path" );
            List<String> classPathElements = new ArrayList<String>();

            if ( classPath != null )
            {
                classPathElements.addAll( Arrays.asList( classPath.getValue().split( " " ) ) );
            }
            else
            {
                classPath = new Attribute( "Class-Path", "" );
                mf.getMainSection().addConfiguredAttribute( classPath );
            }

            // Modify the classpath entries in the manifest
            for ( EarModule o : getModules() )
            {
                if ( o instanceof JarModule )
                {
                    JarModule jm = (JarModule) o;

                    if ( module.getLibDir() != null )
                    {
                        File artifact =
                            new File( new File( workDirectory, module.getLibDir() ), jm.getBundleFileName() );

                        if ( artifact.exists() )
                        {
                            if ( !artifact.delete() )
                            {
                                getLog().error( "Could not delete '" + artifact + "'" );
                            }
                        }
                    }

                    if ( classPathElements.contains( jm.getBundleFileName() ) )
                    {
                        classPathElements.set( classPathElements.indexOf( jm.getBundleFileName() ), jm.getUri() );
                    }
                    else
                    {
                        classPathElements.add( jm.getUri() );
                    }
                }
            }
            classPath.setValue( StringUtils.join( classPathElements.iterator(), " " ) );

            // Write the manifest to disk
            PrintWriter pw = new PrintWriter( manifestFile );
            mf.write( pw );
            pw.close();

            if ( original.isFile() )
            {
                // Pack up the archive again from the work directory
View Full Code Here

    {
        if ( archiveConfiguration != null )
        {
            try
            {
                Manifest manifest;
                final File manifestFile = archiveConfiguration.getManifestFile();

                if ( manifestFile != null )
                {
                    Reader manifestFileReader = null;
                    try
                    {
                        manifestFileReader = new InputStreamReader( new FileInputStream( manifestFile ), "UTF-8" );
                        manifest = new Manifest( manifestFileReader );
                    }
                    catch ( final FileNotFoundException e )
                    {
                        throw new ArchiverException( "Manifest not found: " + e.getMessage(), e );
                    }
View Full Code Here

     */
    public Manifest getManifest( MavenProject project, ManifestConfiguration config )
        throws ManifestException, DependencyResolutionRequiredException
    {
        // Added basic entries
        Manifest m = new Manifest();
        Manifest.Attribute buildAttr = new Manifest.Attribute( "Built-By", System.getProperty( "user.name" ) );
        m.addConfiguredAttribute( buildAttr );
        Manifest.Attribute createdAttr = new Manifest.Attribute( "Created-By", "Apache Maven" );
        m.addConfiguredAttribute( createdAttr );

/* TODO: rethink this, it wasn't working
        Artifact projectArtifact = project.getArtifact();

        if ( projectArtifact.isSnapshot() )
        {
            Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" +
                project.getSnapshotDeploymentBuildNumber() );
            m.addConfiguredAttribute( buildNumberAttr );
        }

*/
        if ( config.getPackageName() != null )
        {
            Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
            m.addConfiguredAttribute( packageAttr );
        }

        Manifest.Attribute buildJdkAttr = new Manifest.Attribute( "Build-Jdk", System.getProperty( "java.version" ) );
        m.addConfiguredAttribute( buildJdkAttr );

        if ( config.isAddClasspath() )
        {
            StringBuffer classpath = new StringBuffer();
            List artifacts = project.getRuntimeClasspathElements();
            String classpathPrefix = config.getClasspathPrefix();

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                File f = new File( (String) iter.next() );
                if ( f.isFile() )
                {
                    if ( classpath.length() > 0 )
                    {
                        classpath.append( " " );
                    }

                    classpath.append( classpathPrefix );
                    classpath.append( f.getName() );
                }
            }

            if ( classpath.length() > 0 )
            {
                Manifest.Attribute classpathAttr = new Manifest.Attribute( "Class-Path", classpath.toString() );
                m.addConfiguredAttribute( classpathAttr );
            }
        }

        // Added supplementary entries
        Manifest.Attribute extensionNameAttr = new Manifest.Attribute( "Extension-Name", project.getArtifactId() );
        m.addConfiguredAttribute( extensionNameAttr );

        if ( project.getDescription() != null )
        {
            Manifest.Attribute specificationTitleAttr = new Manifest.Attribute( "Specification-Title",
                                                                                project.getDescription() );
            m.addConfiguredAttribute( specificationTitleAttr );
        }

        if ( project.getOrganization() != null )
        {
            Manifest.Attribute specificationVendor = new Manifest.Attribute( "Specification-Vendor",
                                                                             project.getOrganization().getName() );
            m.addConfiguredAttribute( specificationVendor );
            Manifest.Attribute implementationVendorAttr = new Manifest.Attribute( "Implementation-Vendor",
                                                                                  project.getOrganization().getName() );
            m.addConfiguredAttribute( implementationVendorAttr );
        }

        Manifest.Attribute implementationTitleAttr = new Manifest.Attribute( "Implementation-Title",
                                                                             project.getArtifactId() );
        m.addConfiguredAttribute( implementationTitleAttr );
        Manifest.Attribute implementationVersionAttr = new Manifest.Attribute( "Implementation-Version",
                                                                               project.getVersion() );
        m.addConfiguredAttribute( implementationVersionAttr );

        String mainClass = config.getMainClass();
        if ( mainClass != null && !"".equals( mainClass ) )
        {
            Manifest.Attribute mainClassAttr = new Manifest.Attribute( "Main-Class", mainClass );
            m.addConfiguredAttribute( mainClassAttr );
        }

        // Added extensions
        if ( config.isAddExtensions() )
        {
            StringBuffer extensionsList = new StringBuffer();
            Set artifacts = project.getArtifacts();

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                Artifact artifact = (Artifact) iter.next();
                if ( "test".equals( artifact.getScope() ) )
                {
                    continue;
                }
                // TODO: type of ejb should be added too?
                if ( "jar".equals( artifact.getType() ) )
                {
                    if ( extensionsList.length() > 0 )
                    {
                        extensionsList.append( " " );
                    }
                    extensionsList.append( artifact.getArtifactId() );
                }
            }

            if ( extensionsList.length() > 0 )
            {
                Manifest.Attribute extensionsListAttr = new Manifest.Attribute( "Extension-List",
                                                                                extensionsList.toString() );
                m.addConfiguredAttribute( extensionsListAttr );
            }

            for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
            {
                Artifact artifact = (Artifact) iter.next();
                if ( "jar".equals( artifact.getType() ) )
                {
                    Manifest.Attribute archExtNameAttr = new Manifest.Attribute(
                        artifact.getArtifactId() + "-Extension-Name", artifact.getArtifactId() );
                    m.addConfiguredAttribute( archExtNameAttr );
                    String name = artifact.getArtifactId() + "-Implementation-Version";
                    Manifest.Attribute archImplVersionAttr = new Manifest.Attribute( name, artifact.getVersion() );
                    m.addConfiguredAttribute( archImplVersionAttr );

                    if ( artifact.getRepository() != null )
                    {
                        // TODO: is this correct
                        name = artifact.getArtifactId() + "-Implementation-URL";
                        String url = artifact.getRepository().getUrl() + "/" + artifact.toString();
                        Manifest.Attribute archImplUrlAttr = new Manifest.Attribute( name, url );
                        m.addConfiguredAttribute( archImplUrlAttr );
                    }
                }
            }
        }

View Full Code Here

        if ( manifestFile != null )
        {
            archiver.setManifest( manifestFile );
        }

        Manifest manifest = getManifest( workingProject, archiveConfiguration.getManifest() );

        // any custom manifest entries in the archive configuration manifest?
        if ( !archiveConfiguration.isManifestEntriesEmpty() )
        {
            Map entries = archiveConfiguration.getManifestEntries();
            Set keys = entries.keySet();
            for ( Iterator iter = keys.iterator(); iter.hasNext(); )
            {
                String key = (String) iter.next();
                String value = (String) entries.get( key );
                Manifest.Attribute attr = new Manifest.Attribute( key, value );
                manifest.addConfiguredAttribute( attr );
            }
        }

        // any custom manifest sections in the archive configuration manifest?
        if ( !archiveConfiguration.isManifestSectionsEmpty() )
        {
          List sections = archiveConfiguration.getManifestSections();
          for ( Iterator iter = sections.iterator(); iter.hasNext(); )
          {
            ManifestSection section = (ManifestSection) iter.next();
            Manifest.Section theSection = new Manifest.Section();
            theSection.setName( section.getName() );
           
            if( !section.isManifestEntriesEmpty() ) {
              Map entries = section.getManifestEntries();
              Set keys = entries.keySet();
              for ( Iterator it = keys.iterator(); it.hasNext(); )
              {
                        String key = (String) it.next();
                        String value = (String) entries.get( key );
                        Manifest.Attribute attr = new Manifest.Attribute( key, value );
                theSection.addConfiguredAttribute( attr );
              }
            }
           
            manifest.addConfiguredSection( theSection );
          }
        }
       
        // Configure the jar
        archiver.addConfiguredManifest( manifest );
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.archiver.jar.Manifest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.