aoqi@0: /* aoqi@0: * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: package com.sun.tools.sjavac.comp; aoqi@0: aoqi@0: import java.util.StringTokenizer; aoqi@0: aoqi@0: import com.sun.tools.javac.main.JavaCompiler; aoqi@0: import com.sun.tools.javac.util.Context; aoqi@0: import com.sun.tools.javac.code.Symbol.ClassSymbol; aoqi@0: import com.sun.tools.sjavac.server.CompilerThread; aoqi@0: import java.io.File; aoqi@0: aoqi@0: /** Subclass to Resolve that overrides collect. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own aoqi@0: * risk. This code and its internal interfaces are subject to change aoqi@0: * or deletion without notice.

aoqi@0: */ aoqi@0: public class JavaCompilerWithDeps extends JavaCompiler { aoqi@0: aoqi@0: /** The dependency database aoqi@0: */ aoqi@0: protected Dependencies deps; aoqi@0: protected CompilerThread compilerThread; aoqi@0: aoqi@0: public JavaCompilerWithDeps(Context context, CompilerThread t) { aoqi@0: super(context); aoqi@0: deps = Dependencies.instance(context); aoqi@0: compilerThread = t; aoqi@0: needRootClasses = true; aoqi@0: } aoqi@0: aoqi@0: public static void preRegister(Context context, final CompilerThread t) { aoqi@0: context.put(compilerKey, new Context.Factory() { aoqi@0: public JavaCompiler make(Context c) { aoqi@0: JavaCompiler instance = new JavaCompilerWithDeps(c, t); aoqi@0: c.put(JavaCompiler.class, instance); aoqi@0: return instance; aoqi@0: } aoqi@0: }); aoqi@0: } aoqi@0: aoqi@0: /** Collect the public apis of classes supplied explicitly for compilation. aoqi@0: * @param sym The class to visit. aoqi@0: */ aoqi@0: @Override aoqi@0: public void reportPublicApi(ClassSymbol sym) { aoqi@0: // The next test will catch when source files are located in the wrong directory! aoqi@0: // This ought to be moved into javac as a new warning, or perhaps as part aoqi@0: // of the auxiliary class warning. aoqi@0: aoqi@0: // For example if sun.swing.BeanInfoUtils aoqi@0: // is in fact stored in: /mybuild/jdk/gensrc/javax/swing/beaninfo/BeanInfoUtils.java aoqi@0: aoqi@0: // We do not need to test that BeanInfoUtils is stored in a file named BeanInfoUtils aoqi@0: // since this is checked earlier. aoqi@0: if (sym.sourcefile != null) { aoqi@0: // Rewrite sun.swing.BeanInfoUtils into /sun/swing/ aoqi@0: StringBuilder pathb = new StringBuilder(); aoqi@0: StringTokenizer qn = new StringTokenizer(sym.packge().toString(), "."); aoqi@0: boolean first = true; aoqi@0: while (qn.hasMoreTokens()) { aoqi@0: String o = qn.nextToken(); aoqi@0: pathb.append("/"); aoqi@0: pathb.append(o); aoqi@0: first = false; aoqi@0: } aoqi@0: pathb.append("/"); aoqi@0: String path = pathb.toString(); aoqi@0: aoqi@0: // Now cut the uri to be: file:///mybuild/jdk/gensrc/javax/swing/beaninfo/ aoqi@0: String p = sym.sourcefile.toUri().getPath(); aoqi@0: // Do not use File.separatorChar here, a URI always uses slashes /. aoqi@0: int i = p.lastIndexOf("/"); aoqi@0: String pp = p.substring(0,i+1); aoqi@0: aoqi@0: // Now check if the truncated uri ends with the path. (It does not == failure!) aoqi@0: if (path.length() > 0 && !path.equals("/unnamed package/") && !pp.endsWith(path)) { aoqi@0: compilerThread.logError("Error: The source file "+sym.sourcefile.getName()+ aoqi@0: " is located in the wrong package directory, because it contains the class "+ aoqi@0: sym.getQualifiedName()); aoqi@0: } aoqi@0: } aoqi@0: deps.visitPubapi(sym); aoqi@0: } aoqi@0: }