From 44e7af7f6580cfcc701c8601122443b43d2312f6 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Tue, 28 Oct 2014 17:04:05 +0300 Subject: [PATCH] K2JS: get rid of MetaInfServices --- .../jetbrains/jet/cli/js/K2JSCompiler.java | 12 +-- .../ClassPathLibraryDefintionsConfig.java | 48 --------- .../config/ClassPathLibrarySourcesLoader.java | 44 -------- .../k2js/config/MetaInfServices.java | 102 ------------------ 4 files changed, 1 insertion(+), 205 deletions(-) delete mode 100644 js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibraryDefintionsConfig.java delete mode 100644 js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibrarySourcesLoader.java delete mode 100644 js/js.translator/src/org/jetbrains/k2js/config/MetaInfServices.java diff --git a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java index 3f1c01f69af..125c7daa75a 100644 --- a/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java +++ b/compiler/cli/src/org/jetbrains/jet/cli/js/K2JSCompiler.java @@ -97,10 +97,6 @@ public class K2JSCompiler extends CLICompiler { Project project = environmentForJS.getProject(); List sourcesFiles = environmentForJS.getSourceFiles(); - ClassPathLibrarySourcesLoader sourceLoader = new ClassPathLibrarySourcesLoader(project); - List additionalSourceFiles = sourceLoader.findSourceFiles(); - sourcesFiles.addAll(additionalSourceFiles); - if (arguments.verbose) { reportCompiledSourcesList(messageCollector, sourcesFiles); } @@ -222,13 +218,7 @@ public class K2JSCompiler extends CLICompiler { ContainerUtil.addAllNotNull(libraryFiles, arguments.libraryFiles); } - if (!libraryFiles.isEmpty()) { - return new LibrarySourcesConfig(project, moduleId, libraryFiles, ecmaVersion, arguments.sourceMap, inlineEnabled); - } - else { - // lets discover the JS library definitions on the classpath - return new ClassPathLibraryDefintionsConfig(project, moduleId, ecmaVersion, arguments.sourceMap, inlineEnabled); - } + return new LibrarySourcesConfig(project, moduleId, libraryFiles, ecmaVersion, arguments.sourceMap, inlineEnabled); } public static MainCallParameters createMainCallParameters(String main) { diff --git a/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibraryDefintionsConfig.java b/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibraryDefintionsConfig.java deleted file mode 100644 index 02b40bdcb90..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibraryDefintionsConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.config; - -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; - -import java.util.List; - -/** - * A Config implementation which is configured with a directory to find the standard library names from - */ -public class ClassPathLibraryDefintionsConfig extends Config { - // used by maven build - @NotNull - public static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.libraryDefinitions"; - - public ClassPathLibraryDefintionsConfig( - @NotNull Project project, - @NotNull String moduleId, - @NotNull EcmaVersion version, - boolean sourcemap, - boolean inlineEnabled - ) { - super(project, moduleId, version, sourcemap, inlineEnabled); - } - - @NotNull - @Override - public List generateLibFiles() { - return MetaInfServices.loadServicesFiles(META_INF_SERVICES_FILE, getProject()); - } -} diff --git a/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibrarySourcesLoader.java b/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibrarySourcesLoader.java deleted file mode 100644 index cda1478d7fb..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/config/ClassPathLibrarySourcesLoader.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.config; - -import com.intellij.openapi.project.Project; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; - -import java.util.List; - -/** - * A helper class to load the kotlin library sources to be compiled to JavaScript as part of a JavaScript build - */ -public class ClassPathLibrarySourcesLoader { - - // used by maven build - @NotNull - public static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.librarySource"; - @NotNull - private final Project project; - - public ClassPathLibrarySourcesLoader(@NotNull Project project) { - this.project = project; - } - - @NotNull - public List findSourceFiles() { - return MetaInfServices.loadServicesFiles(META_INF_SERVICES_FILE, project); - } -} diff --git a/js/js.translator/src/org/jetbrains/k2js/config/MetaInfServices.java b/js/js.translator/src/org/jetbrains/k2js/config/MetaInfServices.java deleted file mode 100644 index f0fd334fc27..00000000000 --- a/js/js.translator/src/org/jetbrains/k2js/config/MetaInfServices.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2010-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.k2js.config; - -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.psi.JetFile; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.util.*; - -import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory; - -/** - * A helper class to discover a META-INF/services file on the classpath and load the files referenced inside it - */ -public final class MetaInfServices { - private MetaInfServices() { - } - - public static List loadServicesFiles(@NotNull String metaInfServicesFile, @NotNull Project project) { - List libFiles = new ArrayList(); - Set urlsLoaded = new HashSet(); - try { - Enumeration resources = MetaInfServices.class.getClassLoader().getResources(metaInfServicesFile); - loadLibFiles(resources, urlsLoaded, libFiles, project); - resources = Thread.currentThread().getContextClassLoader().getResources(metaInfServicesFile); - loadLibFiles(resources, urlsLoaded, libFiles, project); - } - catch (IOException e) { - throw new IllegalStateException(e); - } - return libFiles; - } - - private static void loadLibFiles(@NotNull Enumeration resources, - @NotNull Set urlsLoaded, - @NotNull List libFiles, - @NotNull Project project) - throws IOException { - while (resources.hasMoreElements()) { - URL url = resources.nextElement(); - if (url != null) { - if (urlsLoaded.add(url)) { - BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - try { - while (true) { - String line = reader.readLine(); - if (line == null) { - break; - } - else { - line = line.trim(); - if (line.length() == 0 || line.startsWith("#")) continue; - // lets try to discover the file - InputStream stream = loadClasspathResource(line); - if (stream != null) { - String text = StringUtil.convertLineSeparators(FileUtil.loadTextAndClose(stream)); - libFiles.add(JetPsiFactory(project).createFile(line, text)); - } - } - } - } - finally { - reader.close(); - } - } - } - } - } - - /** - * Tries to load the given resource name on the classpath - */ - public static InputStream loadClasspathResource(String resourceName) { - InputStream answer = ClassPathLibraryDefintionsConfig.class.getClassLoader().getResourceAsStream(resourceName); - if (answer == null) { - answer = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName); - } - return answer; - } -}