Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
8181087: Module system implementation refresh (6/2017)
Browse files Browse the repository at this point in the history
Reviewed-by: jjg
Contributed-by: [email protected], [email protected]
  • Loading branch information
alanb committed Jun 16, 2017
1 parent 39cd598 commit 73f0d90
Show file tree
Hide file tree
Showing 11 changed files with 438 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,13 @@ private void addVisiblePackages(ModuleSymbol msym,
: null;
DiagnosticPosition pos = env != null ? env.tree.pos() : null;
try {
log.error(pos, Errors.PackageClashFromRequires(msym, packageName,
previousModule, exportsFrom));
if (msym.isUnnamed()) {
log.error(pos, Errors.PackageClashFromRequiresInUnnamed(packageName,
previousModule, exportsFrom));
} else {
log.error(pos, Errors.PackageClashFromRequires(msym, packageName,
previousModule, exportsFrom));
}
} finally {
if (env != null)
log.useSource(origSource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URL;
Expand Down Expand Up @@ -65,6 +66,8 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import javax.lang.model.SourceVersion;
import javax.tools.JavaFileManager;
Expand Down Expand Up @@ -1341,6 +1344,24 @@ private Pair<String,Path> inferModuleName(Path p) {
String moduleName = readModuleName(moduleInfoClass);
return new Pair<>(moduleName, p);
}
Path mf = fs.getPath("META-INF/MANIFEST.MF");
if (Files.exists(mf)) {
try (InputStream in = Files.newInputStream(mf)) {
Manifest man = new Manifest(in);
Attributes attrs = man.getMainAttributes();
if (attrs != null) {
String moduleName = attrs.getValue(new Attributes.Name("Automatic-Module-Name"));
if (moduleName != null) {
if (isModuleName(moduleName)) {
return new Pair<>(moduleName, p);
} else {
log.error(Errors.LocnCantGetModuleNameForJar(p));
return null;
}
}
}
}
}
} catch (ModuleNameReader.BadClassFile e) {
log.error(Errors.LocnBadModuleInfo(p));
return null;
Expand Down Expand Up @@ -1428,6 +1449,22 @@ private String readModuleName(Path path) throws IOException, ModuleNameReader.Ba
}
}

//from jdk.internal.module.Checks:
/**
* Returns {@code true} if the given name is a legal module name.
*/
private boolean isModuleName(String name) {
int next;
int off = 0;
while ((next = name.indexOf('.', off)) != -1) {
String id = name.substring(off, next);
if (!SourceVersion.isName(id))
return false;
off = next+1;
}
String last = name.substring(off);
return SourceVersion.isName(last);
}
}

private class ModuleSourcePathLocationHandler extends BasicLocationHandler {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,10 @@ compiler.err.package.in.other.module=\
compiler.err.package.clash.from.requires=\
module {0} reads package {1} from both {2} and {3}

# 0: name, 1: symbol, 2: symbol
compiler.err.package.clash.from.requires.in.unnamed=\
the unnamed module reads package {0} from both {1} and {2}

# 0: string
compiler.err.module.not.found.in.module.source.path=\
module {0} not found in module source path
Expand Down
4 changes: 1 addition & 3 deletions src/jdk.jdeps/share/classes/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
* @since 9
*/
module jdk.jdeps {
requires java.base;
requires java.compiler;
requires jdk.compiler;
exports com.sun.tools.classfile to
jdk.jlink;
exports com.sun.tools.classfile to jdk.jlink;

provides java.util.spi.ToolProvider with
com.sun.tools.javap.Main.JavapToolProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

// key: compiler.err.package.clash.from.requires.in.unnamed
// options: --add-modules ALL-MODULE-PATH
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package exported;

public class Api1 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

module lib1x {
exports exported;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package exported;

public class Api2 {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

module lib2x {
exports exported;
}
Loading

0 comments on commit 73f0d90

Please sign in to comment.