Class Builder

  • All Implemented Interfaces:
    Constants, Registry, Report, Reporter, java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<java.lang.String>
    Direct Known Subclasses:
    JUnitFramework.BundleBuilder, ProjectBuilder

    public class Builder
    extends Analyzer
    Include-Resource: ( [name '=' ] file )+ Private-Package: package-decl ( ',' package-decl )* Export-Package: package-decl ( ',' package-decl )* Import-Package: package-decl ( ',' package-decl )* @version $Revision: 1.27 $
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • IR_PATTERN

        private static final java.util.regex.Pattern IR_PATTERN
      • xdoNotCopy

        private java.util.regex.Pattern xdoNotCopy
      • sourcePath

        private final java.util.List<java.io.File> sourcePath
      • make

        private final Make make
      • defaultPreProcessMatcher

        private Instructions defaultPreProcessMatcher
      • cachedSystemCalls

        private final java.util.Map<java.lang.Integer,​java.lang.String> cachedSystemCalls
      • fixed

        private static final java.lang.String[] fixed
      • firstUse

        boolean firstUse
      • tree

        private Tree tree
      • GITREF_P

        private static final java.util.regex.Pattern GITREF_P
        #388 Manifest header to get GIT head Get the head commit number. Look for a .git/HEAD file, going up in the file hierarchy. Then get this file, and resolve any symbolic reference.
    • Constructor Detail

      • Builder

        public Builder​(Processor parent)
      • Builder

        public Builder​(Builder parent)
      • Builder

        public Builder()
    • Method Detail

      • build

        public Jar build()
                  throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getBuildJar

        private Jar getBuildJar()
      • doPom

        void doPom​(Jar dot)
            throws java.lang.Exception,
                   java.io.IOException
        Throws:
        java.lang.Exception
        java.io.IOException
      • doDigests

        private void doDigests​(Jar dot)
                        throws java.lang.Exception
        Check if we need to calculate any checksums.
        Parameters:
        dot -
        Throws:
        java.lang.Exception
      • init

        public void init()
                  throws java.lang.Exception
        Allow any local initialization by subclasses before we build.
        Throws:
        java.lang.Exception
      • doWab

        private Jar doWab​(Jar dot)
                   throws java.lang.Exception
        Turn this normal bundle in a web and add any resources.
        Throws:
        java.lang.Exception
      • pathStartsWith

        private static boolean pathStartsWith​(java.lang.String path,
                                              java.lang.String prefix)
      • addWabLib

        private void addWabLib​(Jar dot,
                               java.io.File f,
                               java.lang.String name,
                               java.util.Map<java.lang.String,​java.lang.String> attrs)
                        throws java.lang.Exception
        Add a wab lib to the jar.
        Parameters:
        f -
        Throws:
        java.lang.Exception
      • doSaveManifest

        private void doSaveManifest​(Jar dot)
                             throws java.lang.Exception
        Get the manifest and write it out separately if -savemanifest is set
        Parameters:
        dot -
        Throws:
        java.lang.Exception
      • changedFile

        protected void changedFile​(java.io.File f)
      • sign

        void sign​(Jar jar)
           throws java.lang.Exception
        Sign the jar file. -sign : [ ';' 'password:=' ] [ ';' 'keystore:=' ] [ ';' 'sign-password:=' ] ( ',' ... )*
        Throws:
        java.lang.Exception
      • hasSources

        public boolean hasSources()
      • getExtra

        protected Jar getExtra()
                        throws java.lang.Exception
        Answer extra packages. In this case we implement conditional package. Any
        Overrides:
        getExtra in class Analyzer
        Throws:
        java.lang.Exception
      • analyze

        public void analyze()
                     throws java.lang.Exception
        Intercept the call to analyze and cleanup versions after we have analyzed the setup. We do not want to cleanup if we are going to verify.
        Overrides:
        analyze in class Analyzer
        Throws:
        IOException
        java.lang.Exception
      • doSnapshot

        private java.lang.String doSnapshot​(java.lang.String version)
      • cleanupVersion

        public void cleanupVersion​(Packages packages,
                                   java.lang.String defaultVersion)
      • cleanupVersion

        public void cleanupVersion​(Packages packages,
                                   java.lang.String defaultVersion,
                                   java.lang.String what)
      • addSources

        private void addSources​(Jar dot)
                         throws java.lang.Exception
        Throws:
        java.io.IOException
        java.lang.Exception
      • getSourcePath

        public java.util.Collection<java.io.File> getSourcePath()
      • doVerify

        private void doVerify​(Jar dot)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doExpand

        private void doExpand​(Jar dot)
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doExpand

        private java.util.Set<Instruction> doExpand​(Jar jar,
                                                    MultiMap<java.lang.String,​Jar> index,
                                                    Instructions filter)
                                             throws java.lang.Exception
        Destructively filter the packages from the build up index. This index is used by the Export Package as well as the Private Package
        Throws:
        java.lang.Exception
      • filterFrom

        private java.util.List<Jar> filterFrom​(Instruction from,
                                               java.util.List<Jar> providers)
        Parameters:
        from -
      • copyPackage

        private void copyPackage​(Jar dest,
                                 java.util.List<Jar> providers,
                                 java.lang.String path,
                                 int splitStrategy)
        Copy the package from the providers based on the split package strategy.
      • copy

        private void copy​(Jar dest,
                          Jar srce,
                          java.lang.String path,
                          boolean overwrite)
        Copy
      • diagnostic

        private java.lang.String diagnostic​(java.lang.String pack,
                                            java.util.List<Jar> culprits)
        Analyze the classpath for a split package
      • getSplitStrategy

        private int getSplitStrategy​(java.lang.String type)
      • matches

        private Instruction matches​(Instructions instructions,
                                    java.lang.String pack,
                                    java.util.Set<Instruction> unused,
                                    java.lang.String source)
        Matches the instructions against a package.
        Parameters:
        instructions - The list of instructions
        pack - The name of the package
        unused - The total list of patterns, matched patterns are removed
        source - The name of the source container, can be filtered upon with the from: directive.
      • doIncludeResources

        private void doIncludeResources​(Jar jar)
                                 throws java.lang.Exception
        Parse the Bundle-Includes header. Files in the bundles Include header are included in the jar. The source can be a directory or a file.
        Throws:
        java.io.IOException
        java.io.FileNotFoundException
        java.lang.Exception
      • doIncludeResource

        private void doIncludeResource​(Jar jar,
                                       java.lang.String includes)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doIncludeResource

        private void doIncludeResource​(Jar jar,
                                       Parameters clauses)
                                throws java.util.zip.ZipException,
                                       java.io.IOException,
                                       java.lang.Exception
        Throws:
        java.util.zip.ZipException
        java.io.IOException
        java.lang.Exception
      • doIncludeResource

        private void doIncludeResource​(Jar jar,
                                       java.lang.String name,
                                       java.util.Map<java.lang.String,​java.lang.String> extra)
                                throws java.util.zip.ZipException,
                                       java.io.IOException,
                                       java.lang.Exception
        Throws:
        java.util.zip.ZipException
        java.io.IOException
        java.lang.Exception
      • doClassAttribute

        private void doClassAttribute​(Jar jar,
                                      java.lang.String name,
                                      java.util.Map<java.lang.String,​java.lang.String> extra,
                                      Instructions preprocess,
                                      boolean absentIsOk)
                               throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getPreProcessMatcher

        private Instructions getPreProcessMatcher​(java.util.Map<java.lang.String,​java.lang.String> extra)
      • doCommand

        private void doCommand​(Jar jar,
                               java.lang.String source,
                               java.lang.String destination,
                               java.util.Map<java.lang.String,​java.lang.String> extra,
                               Instructions preprocess,
                               boolean absentIsOk)
                        throws java.lang.Exception
        It is possible in Include-Resource to use a system command that generates the contents, this is indicated with cmd attribute. The command can be repeated for a number of source files with the for attribute which indicates a list of repetitions, often down with the Macro._lsa(String[]) or Macro#_lsb(String[]) macro. The repetition will repeat the given command for each item. The @} macro can be used to replace the current item. If no for is given, the source is used as the only item. If the destination contains a macro, each iteration will create a new file, otherwise the destination name is used.
        Parameters:
        jar -
        source -
        destination -
        extra -
        preprocess -
        absentIsOk -
        Throws:
        java.lang.Exception
      • traverse

        private void traverse​(java.util.List<java.lang.String> paths,
                              java.io.File item)
      • findLastModifiedWhileOlder

        private long findLastModifiedWhileOlder​(java.io.File file,
                                                long lastModified)
        Check if a file or directory is older than the given time.
        Parameters:
        file -
        lastModified -
      • doResourceDirectory

        private java.lang.String doResourceDirectory​(Jar jar,
                                                     java.util.Map<java.lang.String,​java.lang.String> extra,
                                                     Instructions preprocess,
                                                     java.io.File sourceFile,
                                                     java.lang.String destinationPath)
                                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • resolveFiles

        private void resolveFiles​(java.io.File dir,
                                  java.io.FileFilter filter,
                                  boolean recursive,
                                  java.lang.String path,
                                  java.util.Map<java.lang.String,​java.io.File> files,
                                  boolean flatten)
      • noSuchFile

        private void noSuchFile​(Jar jar,
                                java.lang.String clause,
                                java.util.Map<java.lang.String,​java.lang.String> extra,
                                java.lang.String source,
                                java.lang.String destinationPath)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • extractFromJar

        private void extractFromJar​(Jar jar,
                                    java.lang.String source,
                                    java.lang.String destination,
                                    boolean absentIsOk)
                             throws java.util.zip.ZipException,
                                    java.io.IOException
        Extra resources from a Jar and add them to the given jar.
        Throws:
        java.util.zip.ZipException
        java.io.IOException
      • addAll

        public boolean addAll​(Jar to,
                              Jar sub,
                              Instruction filter)
        Add all the resources in the given jar that match the given filter.
        Parameters:
        sub - the jar
        filter - a pattern that should match the resoures in sub to be added
      • addAll

        public boolean addAll​(Jar to,
                              Jar sub,
                              Instruction filter,
                              java.lang.String destination)
        Add all the resources in the given jar that match the given filter.
        Parameters:
        sub - the jar
        filter - a pattern that should match the resoures in sub to be added
      • copy

        private void copy​(Jar jar,
                          java.lang.String path,
                          java.io.File from,
                          Instructions preprocess,
                          java.util.Map<java.lang.String,​java.lang.String> extra)
                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • copy

        private void copy​(Jar jar,
                          java.lang.String path,
                          Resource resource,
                          java.util.Map<java.lang.String,​java.lang.String> extra)
      • setSourcepath

        public void setSourcepath​(java.io.File[] files)
      • addSourcepath

        public void addSourcepath​(java.io.File cp)
      • builds

        public Jar[] builds()
                     throws java.lang.Exception
        Build Multiple jars. If the -sub command is set, we filter the file with the given patterns.
        Throws:
        java.lang.Exception
      • startBuild

        protected void startBuild​(Builder builder)
                           throws java.lang.Exception
        Called when we start to build a builder
        Throws:
        java.lang.Exception
      • doneBuild

        protected void doneBuild​(Builder builder)
                          throws java.lang.Exception
        Called when we're done with a builder
        Throws:
        java.lang.Exception
      • getSubBuilders

        public java.util.List<Builder> getSubBuilders()
                                               throws java.lang.Exception
        Answer a list of builders that represent this file or a list of files specified in -sub. This list can be empty. These builders represents to be created artifacts and are each scoped to such an artifacts. The builders can be used to build the bundles or they can be used to find out information about the to be generated bundles.
        Returns:
        List of 0..n builders representing artifacts.
        Throws:
        java.lang.Exception
      • getSubBuilder

        public Builder getSubBuilder​(java.io.File file)
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getSubBuilder

        public Builder getSubBuilder()
                              throws java.lang.Exception
        Throws:
        java.lang.Exception
      • _maven_version

        public java.lang.String _maven_version​(java.lang.String[] args)
        A macro to convert a maven version to an OSGi version
      • _permissions

        public java.lang.String _permissions​(java.lang.String[] args)
      • removeBundleSpecificHeaders

        public void removeBundleSpecificHeaders()
      • isInScope

        public boolean isInScope​(java.util.Collection<java.io.File> resources)
                          throws java.lang.Exception
        Check if the given resource is in scope of this bundle. That is, it checks if the Include-Resource includes this resource or if it is a class file it is on the class path and the Export-Package or Private-Package include this resource.
        Throws:
        java.lang.Exception
      • getIncludedResourcePrefixes

        private java.util.stream.Stream<java.lang.String> getIncludedResourcePrefixes()
        Extra the paths for the directories and files that are used in the Include-Resource header.
      • getClasspathEntrySuffix

        public java.lang.String getClasspathEntrySuffix​(java.io.File resource)
                                                 throws java.lang.Exception
        Answer the string of the resource that it has in the container. It is possible that the resource is a classpath entry. In that case an empty string is returned.
        Parameters:
        resource - The resource to look for
        Returns:
        A suffix on the classpath or "" if the resource is a class path entry
        Throws:
        java.lang.Exception
      • doNotCopy

        public boolean doNotCopy​(java.lang.String v)
        doNotCopy The doNotCopy variable maintains a patter for files that should not be copied. There is a default Constants.DEFAULT_DO_NOT_COPY but this ca be overridden with the Constants.DONOTCOPY property.
      • doNotCopy

        public boolean doNotCopy​(java.io.File from)
      • getDoNotCopy

        public java.util.regex.Pattern getDoNotCopy()
      • setTypeSpecificPlugins

        protected void setTypeSpecificPlugins​(java.util.Set<java.lang.Object> list)
        Overrides:
        setTypeSpecificPlugins in class Analyzer
      • doDiff

        public void doDiff​(Jar dot)
                    throws java.lang.Exception
        Diff this bundle to another bundle for the given packages.
        Throws:
        java.lang.Exception
      • show

        private void show​(Diff p,
                          java.lang.String indent,
                          boolean warning)
        Show the diff recursively
      • addSourcepath

        public void addSourcepath​(java.util.Collection<java.io.File> sourcepath)
      • doBaseline

        protected void doBaseline​(Jar dot)
                           throws java.lang.Exception
        Base line against a previous version. Should be overridden in the ProjectBuilder where we have access to the repos
        Throws:
        java.lang.Exception
      • _githead

        public java.lang.String _githead​(java.lang.String[] args)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • report

        public void report​(java.util.Map<java.lang.String,​java.lang.Object> table)
                    throws java.lang.Exception
        Create a report of the settings
        Overrides:
        report in class Analyzer
        Throws:
        java.lang.Exception
      • system

        public java.lang.String system​(boolean allowFail,
                                       java.lang.String command,
                                       java.lang.String input)
                                throws java.io.IOException,
                                       java.lang.InterruptedException
        We override system so that, for the duration of a build operation, we may cache the result of a given system call. In a large build with many 'make' build jars, such as some OSGi CT build projects, we may call system hundreds of time to compute headers based upon git information such as 'git describe'. Since this information will not change during the course of a single build operation, we cache results to only call once.
        Overrides:
        system in class Processor
        Throws:
        java.io.IOException
        java.lang.InterruptedException