View Javadoc
1   package org.djunits.cleanup;
2   
3   import java.io.File;
4   import java.io.IOException;
5   import java.net.URISyntaxException;
6   import java.nio.charset.StandardCharsets;
7   import java.nio.file.Files;
8   import java.nio.file.Paths;
9   import java.util.List;
10  
11  /**
12   * Utility to clean the .classfile files for all projects; the excludes=** will be removed. Run this class only from
13   * Eclipse!<br>
14   * <br>
15   * Copyright (c) 2003-2020 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See
16   * for project information <a href="https://www.simulation.tudelft.nl/" target="_blank">www.simulation.tudelft.nl</a>. The
17   * source code and binary code of this software is proprietary information of Delft University of Technology.
18   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
19   */
20  public final class CleanClassfileFiles
21  {
22      /** */
23      private CleanClassfileFiles()
24      {
25          // utility class
26      }
27  
28      /**
29       * @param args String[]; none
30       * @throws IOException on I/O error
31       * @throws URISyntaxException on I/O error
32       */
33      public static void main(final String[] args) throws IOException, URISyntaxException
34      {
35          File classFolder = new File(CleanClassfileFiles.class.getResource("/").toURI());
36          File workspaceFolder = classFolder.getParentFile().getParentFile().getParentFile();
37          for (File projectFolder : workspaceFolder.listFiles())
38          {
39              if (projectFolder.isDirectory() && projectFolder.getName().startsWith("dju")
40                      && new File(projectFolder, ".classpath").exists())
41              {
42                  boolean changed = false;
43                  File classPathFile = new File(projectFolder, ".classpath");
44                  List<String> lines = Files.readAllLines(Paths.get(classPathFile.toURI()), StandardCharsets.UTF_8);
45                  for (int index = 0; index < lines.size(); index++)
46                  {
47                      String line = lines.get(index);
48                      if (line.contains("src/main/resources") && line.contains("excluding=\"**\""))
49                      {
50                          line = line.replace("excluding=\"**\" ", "");
51                          lines.set(index, line);
52                          changed = true;
53                      }
54                  }
55                  if (changed)
56                  {
57                      Files.write(Paths.get(classPathFile.toURI()), lines);
58                      System.out.println("Changed: " + projectFolder.toString());
59                  }
60              }
61          }
62      }
63  
64  }