# IGNITE-141 - Minor
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bf013a37 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bf013a37 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bf013a37 Branch: refs/heads/ignite-394 Commit: bf013a3750af9f6025966b597702d90ec8b631fd Parents: 531533d Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Tue Mar 10 15:22:46 2015 -0700 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Tue Mar 10 15:22:46 2015 -0700 ---------------------------------------------------------------------- modules/core/pom.xml | 43 ++-- .../ignite/internal/ClassesGenerator.java | 234 ------------------- .../resources/META-INF/classnames.properties | 3 - .../ignite/tools/classgen/ClassesGenerator.java | 214 +++++++++++++++++ 4 files changed, 244 insertions(+), 250 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf013a37/modules/core/pom.xml ---------------------------------------------------------------------- diff --git a/modules/core/pom.xml b/modules/core/pom.xml index c06a675..42c892d 100644 --- a/modules/core/pom.xml +++ b/modules/core/pom.xml @@ -163,17 +163,19 @@ </goals> </execution> </executions> - <!--<configuration>--> - <!--<excludes>--> - <!--<exclude>**/ClassesGenerator*</exclude>--> - <!--</excludes>--> - <!--</configuration>--> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.3.2</version> + <dependencies> + <dependency> + <groupId>org.apache.ignite</groupId> + <artifactId>ignite-tools</artifactId> + <version>${ignite.version}</version> + </dependency> + </dependencies> <executions> <execution> <phase>process-classes</phase> @@ -181,9 +183,31 @@ <goal>java</goal> </goals> <configuration> - <mainClass>org.apache.ignite.internal.ClassesGenerator</mainClass> + <includePluginDependencies>true</includePluginDependencies> + <mainClass>org.apache.ignite.tools.classgen.ClassesGenerator</mainClass> <arguments> <argument>${project.basedir}/target/classes</argument> + <argument> + <![CDATA[ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +# + ]]> + </argument> + <argument>org.apache.ignite:org.jdk8.backport:org.pcollections:com.romix.scala</argument> </arguments> </configuration> </execution> @@ -205,13 +229,6 @@ <artifactId>maven-antrun-plugin</artifactId> <version>1.7</version> <inherited>false</inherited> - <dependencies> - <dependency> - <groupId>org.apache.ignite</groupId> - <artifactId>ignite-tools</artifactId> - <version>${ignite.version}</version> - </dependency> - </dependencies> <executions> <execution> <id>properties-augmentation</id> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf013a37/modules/core/src/main/java/org/apache/ignite/internal/ClassesGenerator.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/ClassesGenerator.java b/modules/core/src/main/java/org/apache/ignite/internal/ClassesGenerator.java deleted file mode 100644 index 982e83c..0000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/ClassesGenerator.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.ignite.internal; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.apache.ignite.lang.*; - -import java.io.*; -import java.lang.reflect.*; -import java.net.*; -import java.util.*; -import java.util.jar.*; - -/** - * Serialized classes generator. - */ -public class ClassesGenerator { - /** */ - private static final String FILE_PATH = "META-INF/classnames.properties"; - - /** */ - private static final String DFLT_BASE_PATH = U.getIgniteHome() + "/modules/core/src/main/resources"; - - /** */ - private static final String HEADER = - "#\n" + - "# Licensed to the Apache Software Foundation (ASF) under one or more\n" + - "# contributor license agreements. See the NOTICE file distributed with\n" + - "# this work for additional information regarding copyright ownership.\n" + - "# The ASF licenses this file to You under the Apache License, Version 2.0\n" + - "# (the \"License\"); you may not use this file except in compliance with\n" + - "# the License. You may obtain a copy of the License at\n" + - "#\n" + - "# http://www.apache.org/licenses/LICENSE-2.0\n" + - "#\n" + - "# Unless required by applicable law or agreed to in writing, software\n" + - "# distributed under the License is distributed on an \"AS IS\" BASIS,\n" + - "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + - "# See the License for the specific language governing permissions and\n" + - "# limitations under the License.\n" + - "#"; - - /** */ - private static final String[] PACKAGES = { - "org.apache.ignite", - "org.jdk8.backport", - "org.pcollections", - "com.romix.scala" - }; - - /** - * @param args Arguments. - * @throws Exception In case of error. - */ - public static void main(String[] args) throws Exception { - String basePath = args.length > 0 ? args[0] : DFLT_BASE_PATH; - - ClassesGenerator gen = new ClassesGenerator(basePath, HEADER, PACKAGES); - - gen.generate(); - } - - /** */ - private final URLClassLoader ldr = (URLClassLoader)getClass().getClassLoader(); - - /** */ - private final Collection<Class> classes = new TreeSet<>(new Comparator<Class>() { - @Override public int compare(Class c1, Class c2) { - return c1.getName().compareTo(c2.getName()); - } - }); - - /** */ - private final Collection<String> errs = new ArrayList<>(); - - /** */ - private final String basePath; - - /** */ - private final String header; - - /** */ - private final String[] packages; - - /** - * @param basePath Base file path. - * @param header Header. - * @param packages Included packages. - */ - public ClassesGenerator(String basePath, String header, String[] packages) { - this.basePath = basePath; - this.header = header; - this.packages = packages; - } - - /** - * @throws Exception In case of error. - */ - public void generate() throws Exception { - System.out.println("Generating classnames.properties..."); - - for (URL url : ldr.getURLs()) - processUrl(url); - - if (!errs.isEmpty()) { - StringBuilder sb = new StringBuilder("Failed to generate classnames.properties due to errors:\n"); - - for (String err : errs) - sb.append(" ").append(err).append('\n'); - - throw new Exception(sb.toString().trim()); - } - - PrintStream out = new PrintStream(new File(basePath, FILE_PATH)); - - out.println(header); - out.println(); - - for (Class cls : classes) - out.println(cls.getName()); - } - - /** - * @param url URL. - * @throws Exception In case of error. - */ - private void processUrl(URL url) throws Exception { - System.out.println(" Processing URL: " + url); - - File file = new File(url.toURI()); - - int prefixLen = file.getPath().length() + 1; - - processFile(file, prefixLen); - } - - /** - * @param file File. - * @throws Exception In case of error. - */ - private void processFile(File file, int prefixLen) throws Exception { - if (!file.exists()) - throw new FileNotFoundException("File doesn't exist: " + file); - - if (file.isDirectory()) { - for (File f : file.listFiles()) - processFile(f, prefixLen); - } - else { - assert file.isFile(); - - String path = file.getPath(); - - if (path.toLowerCase().endsWith(".jar")) { - try (JarInputStream jin = new JarInputStream(new BufferedInputStream(new FileInputStream(path)))) { - JarEntry entry; - - while ((entry = jin.getNextJarEntry()) != null) { - if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".class")) - processClassFile(entry.getName(), 0); - } - } - } - else if (path.toLowerCase().endsWith(".class")) - processClassFile(path, prefixLen); - } - } - - /** - * @param path File path. - * @param prefixLen Prefix length. - * @throws Exception In case of error. - */ - private void processClassFile(String path, int prefixLen) - throws Exception { - String clsName = path.substring(prefixLen, path.length() - 6).replace(File.separatorChar, '.'); - - boolean included = false; - - for (String pkg : packages) { - if (clsName.startsWith(pkg)) { - included = true; - - break; - } - } - - if (included) { - Class<?> cls = Class.forName(clsName, false, ldr); - - if (Serializable.class.isAssignableFrom(cls) && !IgniteFuture.class.isAssignableFrom(cls) && - !IgniteInternalFuture.class.isAssignableFrom(cls) && !GridClientFuture.class.isAssignableFrom(cls)) { - if (!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers()) && !cls.isEnum() && - !cls.getSimpleName().isEmpty() && cls.getName().startsWith("org.apache.ignite")) { - try { - Field field = cls.getDeclaredField("serialVersionUID"); - - if (!field.getType().equals(long.class)) - errs.add("serialVersionUID field is not long in class: " + cls.getName()); - - int mod = field.getModifiers(); - - if (!Modifier.isStatic(mod)) - errs.add("serialVersionUID field is not static in class: " + cls.getName()); - - if (!Modifier.isFinal(mod)) - errs.add("serialVersionUID field is not final in class: " + cls.getName()); - } - catch (NoSuchFieldException ignored) { - errs.add("No serialVersionUID field in class: " + cls.getName()); - } - } - - classes.add((Class)cls); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf013a37/modules/core/src/main/resources/META-INF/classnames.properties ---------------------------------------------------------------------- diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties index 5df9038..808b6ba 100644 --- a/modules/core/src/main/resources/META-INF/classnames.properties +++ b/modules/core/src/main/resources/META-INF/classnames.properties @@ -1050,7 +1050,6 @@ org.apache.ignite.internal.util.GridSerializableList org.apache.ignite.internal.util.GridSerializableMap org.apache.ignite.internal.util.GridSerializableSet org.apache.ignite.internal.util.GridSetWrapper -org.apache.ignite.internal.util.GridSnapshotLock$Sync org.apache.ignite.internal.util.GridSpiCloseableIteratorWrapper org.apache.ignite.internal.util.GridStringBuilder org.apache.ignite.internal.util.GridSynchronizedMap @@ -1310,7 +1309,6 @@ org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMap$Segment$2 org.apache.ignite.internal.util.offheap.unsafe.GridUnsafePartitionedMap$2 org.apache.ignite.internal.util.offheap.unsafe.GridUnsafePartitionedMap$3 org.apache.ignite.internal.util.snaptree.CopyOnWriteManager$COWEpoch -org.apache.ignite.internal.util.snaptree.CopyOnWriteManager$Latch org.apache.ignite.internal.util.snaptree.Epoch$Root org.apache.ignite.internal.util.snaptree.EpochNode org.apache.ignite.internal.util.snaptree.EpochNode$Child @@ -1599,7 +1597,6 @@ org.apache.ignite.transactions.TransactionTimeoutException org.jdk8.backport.ConcurrentHashMap8 org.jdk8.backport.ConcurrentHashMap8$KeySetView org.jdk8.backport.ConcurrentHashMap8$Segment -org.jdk8.backport.ConcurrentHashMap8$TreeBin org.jdk8.backport.ConcurrentLinkedHashMap$QueuePolicy org.jdk8.backport.ConcurrentLinkedHashMap$Segment org.jdk8.backport.ConcurrentLinkedHashMap$WriteThroughEntry http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bf013a37/modules/tools/src/main/java/org/apache/ignite/tools/classgen/ClassesGenerator.java ---------------------------------------------------------------------- diff --git a/modules/tools/src/main/java/org/apache/ignite/tools/classgen/ClassesGenerator.java b/modules/tools/src/main/java/org/apache/ignite/tools/classgen/ClassesGenerator.java new file mode 100644 index 0000000..68272f7 --- /dev/null +++ b/modules/tools/src/main/java/org/apache/ignite/tools/classgen/ClassesGenerator.java @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.ignite.tools.classgen; + +import java.io.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; +import java.util.concurrent.locks.*; +import java.util.jar.*; + +/** + * Serialized classes generator. + */ +public class ClassesGenerator { + /** */ + private static final String FILE_PATH = "META-INF/classnames.properties"; + + /** */ + private static final String[] EXCLUDED_PACKAGES = { + "org.apache.ignite.tools" + }; + + /** + * @param args Arguments. + * @throws Exception In case of error. + */ + public static void main(String[] args) throws Exception { + assert args.length >= 3; + + String basePath = args[0]; + String header = args[1]; + String[] packages = args[2].split(":"); + + ClassesGenerator gen = new ClassesGenerator(basePath, header, packages); + + gen.generate(); + } + + /** */ + private final URLClassLoader ldr = (URLClassLoader)getClass().getClassLoader(); + + /** */ + private final Collection<Class> classes = new TreeSet<>(new Comparator<Class>() { + @Override public int compare(Class c1, Class c2) { + return c1.getName().compareTo(c2.getName()); + } + }); + + /** */ + private final Collection<String> errs = new ArrayList<>(); + + /** */ + private final String basePath; + + /** */ + private final String header; + + /** */ + private final String[] packages; + + /** + * @param basePath Base file path. + * @param header Header. + * @param packages Included packages. + */ + private ClassesGenerator(String basePath, String header, String[] packages) { + this.basePath = basePath; + this.header = header; + this.packages = packages; + } + + /** + * @throws Exception In case of error. + */ + private void generate() throws Exception { + System.out.println("Generating classnames.properties..."); + + for (URL url : ldr.getURLs()) + processUrl(url); + + if (!errs.isEmpty()) { + StringBuilder sb = new StringBuilder("Failed to generate classnames.properties due to errors:\n"); + + for (String err : errs) + sb.append(" ").append(err).append('\n'); + + throw new Exception(sb.toString().trim()); + } + + PrintStream out = new PrintStream(new File(basePath, FILE_PATH)); + + out.println(header); + out.println(); + + for (Class cls : classes) + out.println(cls.getName()); + } + + /** + * @param url URL. + * @throws Exception In case of error. + */ + private void processUrl(URL url) throws Exception { + System.out.println(" Processing URL: " + url); + + File file = new File(url.toURI()); + + int prefixLen = file.getPath().length() + 1; + + processFile(file, prefixLen); + } + + /** + * @param file File. + * @throws Exception In case of error. + */ + private void processFile(File file, int prefixLen) throws Exception { + if (!file.exists()) + throw new FileNotFoundException("File doesn't exist: " + file); + + if (file.isDirectory()) { + for (File f : file.listFiles()) + processFile(f, prefixLen); + } + else { + assert file.isFile(); + + String path = file.getPath(); + + if (path.toLowerCase().endsWith(".jar")) { + try (JarInputStream jin = new JarInputStream(new BufferedInputStream(new FileInputStream(path)))) { + JarEntry entry; + + while ((entry = jin.getNextJarEntry()) != null) { + if (!entry.isDirectory() && entry.getName().toLowerCase().endsWith(".class")) + processClassFile(entry.getName(), 0); + } + } + } + else if (path.toLowerCase().endsWith(".class")) + processClassFile(path, prefixLen); + } + } + + /** + * @param path File path. + * @param prefixLen Prefix length. + * @throws Exception In case of error. + */ + private void processClassFile(String path, int prefixLen) + throws Exception { + String clsName = path.substring(prefixLen, path.length() - 6).replace(File.separatorChar, '.'); + + for (String pkg : EXCLUDED_PACKAGES) { + if (clsName.startsWith(pkg)) + return; + } + + boolean included = false; + + for (String pkg : packages) { + if (clsName.startsWith(pkg)) { + included = true; + + break; + } + } + + if (included) { + Class<?> cls = Class.forName(clsName, false, ldr); + + if (Serializable.class.isAssignableFrom(cls) && !AbstractQueuedSynchronizer.class.isAssignableFrom(cls)) { + if (!cls.isInterface() && !Modifier.isAbstract(cls.getModifiers()) && !cls.isEnum() && + !cls.getSimpleName().isEmpty() && cls.getName().startsWith("org.apache.ignite")) { + try { + Field field = cls.getDeclaredField("serialVersionUID"); + + if (!field.getType().equals(long.class)) + errs.add("serialVersionUID field is not long in class: " + cls.getName()); + + int mod = field.getModifiers(); + + if (!Modifier.isStatic(mod)) + errs.add("serialVersionUID field is not static in class: " + cls.getName()); + + if (!Modifier.isFinal(mod)) + errs.add("serialVersionUID field is not final in class: " + cls.getName()); + } + catch (NoSuchFieldException ignored) { + errs.add("No serialVersionUID field in class: " + cls.getName()); + } + } + + classes.add((Class)cls); + } + } + } +}