Transformer.java revision 3012:adba44f6b471
11541Srgrimes/*
21541Srgrimes * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41541Srgrimes *
51541Srgrimes * This code is free software; you can redistribute it and/or modify it
61541Srgrimes * under the terms of the GNU General Public License version 2 only, as
71541Srgrimes * published by the Free Software Foundation.  Oracle designates this
81541Srgrimes * particular file as subject to the "Classpath" exception as provided
91541Srgrimes * by Oracle in the LICENSE file that accompanied this code.
101541Srgrimes *
111541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
121541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
151541Srgrimes * accompanied this code).
161541Srgrimes *
171541Srgrimes * You should have received a copy of the GNU General Public License version
181541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
191541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201541Srgrimes *
211541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221541Srgrimes * or visit www.oracle.com if you need additional information or have any
231541Srgrimes * questions.
241541Srgrimes */
251541Srgrimes
261541Srgrimespackage com.sun.tools.sjavac;
271541Srgrimes
281541Srgrimesimport java.io.PrintStream;
291541Srgrimesimport java.net.URI;
301541Srgrimesimport java.util.Map;
311541Srgrimesimport java.util.Set;
321541Srgrimes
331541Srgrimesimport com.sun.tools.sjavac.comp.CompilationService;
341541Srgrimesimport com.sun.tools.sjavac.options.Options;
351541Srgrimesimport com.sun.tools.sjavac.pubapi.PubApi;
361541Srgrimes
371541Srgrimes/**
381541Srgrimes * The transform interface is used to transform content inside a package, from one form to another.
391541Srgrimes * Usually the output form is an unpredictable number of output files. (eg class files)
401541Srgrimes * but can also be an unpredictable number of generated source files (eg idl2java)
411541Srgrimes * or a single predictable output file (eg when copying,cleaning or compiling a properties file).
421541Srgrimes *
431541Srgrimes *  <p><b>This is NOT part of any supported API.
441541Srgrimes *  If you write code that depends on this, you do so at your own risk.
451541Srgrimes *  This code and its internal interfaces are subject to change or
461541Srgrimes *  deletion without notice.</b>
471541Srgrimes */
481541Srgrimespublic interface Transformer {
491541Srgrimes    /**
501541Srgrimes     * The transform method takes a set of package names, mapped to their source files and to the
511541Srgrimes     * pubapis of the packages.
521541Srgrimes     *
531541Srgrimes     * The transform implementation must:
541541Srgrimes     *    store the names of the generated artifacts for each package into package_artifacts
551541Srgrimes     *    store found dependencies to other packages into the supplied set package_dependencies
561541Srgrimes     *    store the public api for a package into the supplied set package_pubapis
571541Srgrimes     *
581541Srgrimes     * Any benign messages as a result of running the transform
591541Srgrimes     * are written into stdout, and errors are written to stderr.
601541Srgrimes     *
611541Srgrimes     * The debug_level can be 0=silent (only warnings and errors) 1=normal 2=verbose 3 or greater=debug
621541Srgrimes     * setExtra is used to set the extra information information that can be passed on
631541Srgrimes     * the command line to the smart javac wrapper.
641541Srgrimes     *
65     * If sjavac is building incrementally from an existing javac_state, the var incremental is true.
66     *
67     * The transformer will only be called if some source in the package (or dependency) has
68     * a modified timestamp. Thus the transformer might get called with many sources, of which
69     * only one has changed. The transformer is allowed to regenerate all artifacts but
70     * a better transformer will only write those artifacts that need updating.
71     *
72     * However the transformer must verify that the existing artifacts really are there!
73     * and it must always update package_artifacts, package_dependencies, and package_pubapis correctly.
74     * This means that at least for Java source, it will always have to recompile the sources.
75     *
76     * The transformer is allowed to put files anywhere in the dest_root.
77     * An example of this is, can be the META-INF transformer that copy files
78     * below META-INF directories to the single META-INF directory below dest_root.
79     *
80     * False is returned if there was an error that prevented the transform.
81     * I.e. something was printed on stderr.
82     *
83     * If num_cores is set to a non-zero value. The transform should attempt to use no more than these
84     * number of threads for heavy work.
85     */
86    boolean transform(CompilationService sjavac,
87                      Map<String,Set<URI>> pkgSrcs,
88                      Set<URI>             visibleSources,
89                      Map<URI,Set<String>> visibleClasses,
90                      Map<String,Set<String>> oldPackageDependencies,
91                      URI destRoot,
92                      Map<String,Set<URI>>    packageArtifacts,
93                      Map<String, Map<String, Set<String>>> packageDependencies,   // Package name -> Fully Qualified Type [from] -> Set of fully qualified type [to]
94                      Map<String, Map<String, Set<String>>> packageCpDependencies, // Package name -> Fully Qualified Type [from] -> Set of fully qualified type [to]
95                      Map<String, PubApi>     packagePublicApis,
96                      Map<String, PubApi>     dependencyApis,
97                      int debugLevel,
98                      boolean incremental,
99                      int numCores,
100                      PrintStream out,
101                      PrintStream err);
102
103    void setExtra(String e);
104    void setExtra(Options args);
105}
106