From 109fe06e5d1e7f17bb4c07727d50df5f55b6307b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 23 Apr 2013 18:16:19 +0300 Subject: Moved WidgetSetBuilder to server as ClassPathExplorer dependends on it (#11591) Change-Id: I1091de12737e242129cd8fb62daba9e2273e67ff --- .../server/widgetsetutils/WidgetSetBuilder.java | 213 --------------------- .../server/widgetsetutils/WidgetSetBuilder.java | 213 +++++++++++++++++++++ 2 files changed, 213 insertions(+), 213 deletions(-) delete mode 100644 client-compiler/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java create mode 100644 server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java diff --git a/client-compiler/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java b/client-compiler/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java deleted file mode 100644 index 3a0e59df71..0000000000 --- a/client-compiler/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2000-2013 Vaadin Ltd. - * - * 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 com.vaadin.server.widgetsetutils; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.io.Reader; -import java.net.URL; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Helper class to update widgetsets GWT module configuration file. Can be used - * command line or via IDE tools. - * - *

- * If module definition file contains text "WS Compiler: manually edited", tool - * will skip editing file. - * - */ -public class WidgetSetBuilder { - - public static void main(String[] args) throws IOException { - if (args.length == 0) { - printUsage(); - } else { - String widgetsetname = args[0]; - updateWidgetSet(widgetsetname); - - } - } - - public static void updateWidgetSet(final String widgetset) - throws IOException, FileNotFoundException { - boolean changed = false; - - Map availableWidgetSets = ClassPathExplorer - .getAvailableWidgetSets(); - - URL sourceUrl = availableWidgetSets.get(widgetset); - if (sourceUrl == null) { - // find first/default source directory - sourceUrl = ClassPathExplorer.getDefaultSourceDirectory(); - } - - String widgetsetfilename = sourceUrl.getFile() + "/" - + widgetset.replace(".", "/") + ".gwt.xml"; - - File widgetsetFile = new File(widgetsetfilename); - if (!widgetsetFile.exists()) { - // create empty gwt module file - File parent = widgetsetFile.getParentFile(); - if (parent != null && !parent.exists()) { - if (!parent.mkdirs()) { - throw new IOException( - "Could not create directory for the widgetset: " - + parent.getPath()); - } - } - widgetsetFile.createNewFile(); - PrintStream printStream = new PrintStream(new FileOutputStream( - widgetsetFile)); - printStream.print("\n" - + "\n"); - printStream.print("\n"); - printStream - .print(" \n" - + " \n"); - printStream.print("\n\n"); - printStream.close(); - changed = true; - } - - String content = readFile(widgetsetFile); - if (isEditable(content)) { - String originalContent = content; - - Collection oldInheritedWidgetsets = getCurrentInheritedWidgetsets(content); - - // add widgetsets that do not exist - Iterator i = availableWidgetSets.keySet().iterator(); - while (i.hasNext()) { - String ws = i.next(); - if (ws.equals(widgetset)) { - // do not inherit the module itself - continue; - } - if (!oldInheritedWidgetsets.contains(ws)) { - content = addWidgetSet(ws, content); - } - } - - for (String ws : oldInheritedWidgetsets) { - if (!availableWidgetSets.containsKey(ws)) { - // widgetset not available in classpath - content = removeWidgetSet(ws, content); - } - } - - changed = changed || !content.equals(originalContent); - if (changed) { - commitChanges(widgetsetfilename, content); - } - } else { - System.out - .println("Widgetset is manually edited. Skipping updates."); - } - } - - private static boolean isEditable(String content) { - return !content.contains("WS Compiler: manually edited"); - } - - private static String removeWidgetSet(String ws, String content) { - return content.replaceFirst("", ""); - } - - private static void commitChanges(String widgetsetfilename, String content) - throws IOException { - BufferedWriter bufferedWriter = new BufferedWriter( - new OutputStreamWriter(new FileOutputStream(widgetsetfilename))); - bufferedWriter.write(content); - bufferedWriter.close(); - } - - private static String addWidgetSet(String ws, String content) { - return content.replace("", "\n " + "\n"); - } - - private static Collection getCurrentInheritedWidgetsets( - String content) { - HashSet hashSet = new HashSet(); - Pattern inheritsPattern = Pattern.compile(" name=\"([^\"]*)\""); - - Matcher matcher = inheritsPattern.matcher(content); - - while (matcher.find()) { - String gwtModule = matcher.group(1); - if (isWidgetset(gwtModule)) { - hashSet.add(gwtModule); - } - } - return hashSet; - } - - static boolean isWidgetset(String gwtModuleName) { - return gwtModuleName.toLowerCase().contains("widgetset"); - } - - private static String readFile(File widgetsetFile) throws IOException { - Reader fi = new FileReader(widgetsetFile); - BufferedReader bufferedReader = new BufferedReader(fi); - StringBuilder sb = new StringBuilder(); - String line; - while ((line = bufferedReader.readLine()) != null) { - sb.append(line); - sb.append("\n"); - } - fi.close(); - return sb.toString(); - } - - private static void printUsage() { - PrintStream o = System.out; - o.println(WidgetSetBuilder.class.getSimpleName() + " usage:"); - o.println(" 1. Set the same classpath as you will " - + "have for the GWT compiler."); - o.println(" 2. Give the widgetsetname (to be created or updated)" - + " as first parameter"); - o.println(); - o.println("All found vaadin widgetsets will be inherited in given widgetset"); - - } - -} diff --git a/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java b/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java new file mode 100644 index 0000000000..3a0e59df71 --- /dev/null +++ b/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java @@ -0,0 +1,213 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * 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 com.vaadin.server.widgetsetutils; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.Reader; +import java.net.URL; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Helper class to update widgetsets GWT module configuration file. Can be used + * command line or via IDE tools. + * + *

+ * If module definition file contains text "WS Compiler: manually edited", tool + * will skip editing file. + * + */ +public class WidgetSetBuilder { + + public static void main(String[] args) throws IOException { + if (args.length == 0) { + printUsage(); + } else { + String widgetsetname = args[0]; + updateWidgetSet(widgetsetname); + + } + } + + public static void updateWidgetSet(final String widgetset) + throws IOException, FileNotFoundException { + boolean changed = false; + + Map availableWidgetSets = ClassPathExplorer + .getAvailableWidgetSets(); + + URL sourceUrl = availableWidgetSets.get(widgetset); + if (sourceUrl == null) { + // find first/default source directory + sourceUrl = ClassPathExplorer.getDefaultSourceDirectory(); + } + + String widgetsetfilename = sourceUrl.getFile() + "/" + + widgetset.replace(".", "/") + ".gwt.xml"; + + File widgetsetFile = new File(widgetsetfilename); + if (!widgetsetFile.exists()) { + // create empty gwt module file + File parent = widgetsetFile.getParentFile(); + if (parent != null && !parent.exists()) { + if (!parent.mkdirs()) { + throw new IOException( + "Could not create directory for the widgetset: " + + parent.getPath()); + } + } + widgetsetFile.createNewFile(); + PrintStream printStream = new PrintStream(new FileOutputStream( + widgetsetFile)); + printStream.print("\n" + + "\n"); + printStream.print("\n"); + printStream + .print(" \n" + + " \n"); + printStream.print("\n\n"); + printStream.close(); + changed = true; + } + + String content = readFile(widgetsetFile); + if (isEditable(content)) { + String originalContent = content; + + Collection oldInheritedWidgetsets = getCurrentInheritedWidgetsets(content); + + // add widgetsets that do not exist + Iterator i = availableWidgetSets.keySet().iterator(); + while (i.hasNext()) { + String ws = i.next(); + if (ws.equals(widgetset)) { + // do not inherit the module itself + continue; + } + if (!oldInheritedWidgetsets.contains(ws)) { + content = addWidgetSet(ws, content); + } + } + + for (String ws : oldInheritedWidgetsets) { + if (!availableWidgetSets.containsKey(ws)) { + // widgetset not available in classpath + content = removeWidgetSet(ws, content); + } + } + + changed = changed || !content.equals(originalContent); + if (changed) { + commitChanges(widgetsetfilename, content); + } + } else { + System.out + .println("Widgetset is manually edited. Skipping updates."); + } + } + + private static boolean isEditable(String content) { + return !content.contains("WS Compiler: manually edited"); + } + + private static String removeWidgetSet(String ws, String content) { + return content.replaceFirst("", ""); + } + + private static void commitChanges(String widgetsetfilename, String content) + throws IOException { + BufferedWriter bufferedWriter = new BufferedWriter( + new OutputStreamWriter(new FileOutputStream(widgetsetfilename))); + bufferedWriter.write(content); + bufferedWriter.close(); + } + + private static String addWidgetSet(String ws, String content) { + return content.replace("", "\n " + "\n"); + } + + private static Collection getCurrentInheritedWidgetsets( + String content) { + HashSet hashSet = new HashSet(); + Pattern inheritsPattern = Pattern.compile(" name=\"([^\"]*)\""); + + Matcher matcher = inheritsPattern.matcher(content); + + while (matcher.find()) { + String gwtModule = matcher.group(1); + if (isWidgetset(gwtModule)) { + hashSet.add(gwtModule); + } + } + return hashSet; + } + + static boolean isWidgetset(String gwtModuleName) { + return gwtModuleName.toLowerCase().contains("widgetset"); + } + + private static String readFile(File widgetsetFile) throws IOException { + Reader fi = new FileReader(widgetsetFile); + BufferedReader bufferedReader = new BufferedReader(fi); + StringBuilder sb = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + sb.append(line); + sb.append("\n"); + } + fi.close(); + return sb.toString(); + } + + private static void printUsage() { + PrintStream o = System.out; + o.println(WidgetSetBuilder.class.getSimpleName() + " usage:"); + o.println(" 1. Set the same classpath as you will " + + "have for the GWT compiler."); + o.println(" 2. Give the widgetsetname (to be created or updated)" + + " as first parameter"); + o.println(); + o.println("All found vaadin widgetsets will be inherited in given widgetset"); + + } + +} -- cgit v1.2.3