Transformer.java revision 2571:10fc81ac75b4
1228753Smm/* 2228753Smm * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. 3228753Smm * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4228753Smm * 5228753Smm * This code is free software; you can redistribute it and/or modify it 6228753Smm * under the terms of the GNU General Public License version 2 only, as 7228753Smm * published by the Free Software Foundation. Oracle designates this 8228753Smm * particular file as subject to the "Classpath" exception as provided 9228753Smm * by Oracle in the LICENSE file that accompanied this code. 10228753Smm * 11228753Smm * This code is distributed in the hope that it will be useful, but WITHOUT 12228753Smm * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13228753Smm * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14228753Smm * version 2 for more details (a copy is included in the LICENSE file that 15228753Smm * accompanied this code). 16228753Smm * 17228753Smm * You should have received a copy of the GNU General Public License version 18228753Smm * 2 along with this work; if not, write to the Free Software Foundation, 19228753Smm * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20228753Smm * 21228753Smm * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22228753Smm * or visit www.oracle.com if you need additional information or have any 23228753Smm * questions. 24228753Smm */ 25228753Smm 26228753Smmpackage com.sun.tools.sjavac; 27228753Smm 28229592Smmimport java.io.PrintStream; 29228753Smmimport java.net.URI; 30228753Smmimport java.util.Set; 31228753Smmimport java.util.Map; 32228753Smm 33228753Smmimport com.sun.tools.sjavac.options.Options; 34228753Smmimport com.sun.tools.sjavac.server.JavacService; 35228753Smm 36228753Smm/** 37228753Smm * The transform interface is used to transform content inside a package, from one form to another. 38228753Smm * Usually the output form is an unpredictable number of output files. (eg class files) 39228753Smm * but can also be an unpredictable number of generated source files (eg idl2java) 40228753Smm * or a single predictable output file (eg when copying,cleaning or compiling a properties file). 41228753Smm * 42228753Smm * <p><b>This is NOT part of any supported API. 43228753Smm * If you write code that depends on this, you do so at your own 44228753Smm * risk. This code and its internal interfaces are subject to change 45228753Smm * or deletion without notice.</b></p> 46228753Smm */ 47228753Smmpublic interface Transformer 48228753Smm{ 49228753Smm /** 50228753Smm * The transform method takes a set of package names, mapped to their source files and to the 51228753Smm * pubapis of the packages. 52228753Smm * 53228753Smm * The transform implementation must: 54228753Smm * store the names of the generated artifacts for each package into package_artifacts 55228753Smm * store found dependencies to other packages into the supplied set package_dependencies 56228753Smm * store the public api for a package into the supplied set package_pubapis 57228753Smm * 58228753Smm * Any benign messages as a result of running the transform 59228753Smm * are written into stdout, and errors are written to stderr. 60228753Smm * 61228753Smm * The debug_level can be 0=silent (only warnings and errors) 1=normal 2=verbose 3 or greater=debug 62228753Smm * setExtra is used to set the extra information information that can be passed on 63228753Smm * the command line to the smart javac wrapper. 64228753Smm * 65228753Smm * If sjavac is building incrementally from an existing javac_state, the var incremental is true. 66228753Smm * 67228753Smm * The transformer will only be called if some source in the package (or dependency) has 68228753Smm * a modified timestamp. Thus the transformer might get called with many sources, of which 69228753Smm * only one has changed. The transformer is allowed to regenerate all artifacts but 70228753Smm * a better transformer will only write those artifacts that need updating. 71228753Smm * 72228753Smm * However the transformer must verify that the existing artifacts really are there! 73228753Smm * and it must always update package_artifacts, package_dependencies, and package_pubapis correctly. 74228753Smm * This means that at least for Java source, it will always have to recompile the sources. 75228753Smm * 76228753Smm * The transformer is allowed to put files anywhere in the dest_root. 77228753Smm * An example of this is, can be the META-INF transformer that copy files 78228753Smm * below META-INF directories to the single META-INF directory below dest_root. 79228753Smm * 80228753Smm * False is returned if there was an error that prevented the transform. 81228753Smm * I.e. something was printed on stderr. 82228753Smm * 83228753Smm * If num_cores is set to a non-zero value. The transform should attempt to use no more than these 84228753Smm * number of threads for heavy work. 85228753Smm */ 86228753Smm boolean transform(JavacService javacService, 87228753Smm Map<String,Set<URI>> pkgSrcs, 88228753Smm Set<URI> visibleSources, 89228753Smm Map<URI,Set<String>> visibleClasses, 90228753Smm Map<String,Set<String>> oldPackageDependencies, 91228753Smm URI destRoot, 92228753Smm Map<String,Set<URI>> packageArtifacts, 93228753Smm Map<String,Set<String>> packageDependencies, 94228753Smm Map<String,String> packagePublicApis, 95228753Smm int debugLevel, 96228753Smm boolean incremental, 97228753Smm int numCores, 98228753Smm PrintStream out, 99228753Smm PrintStream err); 100228753Smm 101228753Smm void setExtra(String e); 102228753Smm void setExtra(Options args); 103228753Smm} 104228753Smm