Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: aded2bd629b8c0843111a88e825c494bb3032555 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
 * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    Eike Stepper - initial API and implementation
 */
package org.eclipse.emf.cdo.releng;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Eike Stepper
 */
public class MovePackageDescriptions
{
  private static final String NL = System.getProperty("line.separator");

  public static void main(String[] args) throws IOException
  {
    String javadocFolder = args[0];
    System.out.println();
    System.out.println("Moving package descriptions in " + new File(javadocFolder).getCanonicalPath());

    movePackageDescriptionsInFolder(new File(javadocFolder));
  }

  private static void movePackageDescriptionsInFolder(File folder) throws IOException
  {
    File[] children = folder.listFiles();
    for (File file : children)
    {
      String name = file.getName();
      if (file.isDirectory())
      {
        if (!name.equals(".svn"))
        {
          movePackageDescriptionsInFolder(file);
        }
      }
      else
      {
        if (name.equals("package-summary.html"))
        {
          movePackageDescription(file);
        }
      }
    }
  }

  private static final Pattern PATTERN = Pattern.compile("(.*</H2>\\s*)" //
      + "(.*<B>See:</B>.*<A HREF=\"#package_description\"><B>Description</B></A>)" // To be replaced...
      + "(.*)" //
      + "(<A NAME=\"package_description\"><!-- --></A><H2>.*</H2>.*<P>\\s*)" //
      + "(.*)" // ... with full description
      + "(<P>\\s*<P>\\s*<DL>\\s*</DL>\\s*<HR>.*)", //
      Pattern.MULTILINE | Pattern.DOTALL);

  private static void movePackageDescription(File file) throws IOException
  {
    FileReader in = null;
    String contents;

    try
    {
      in = new FileReader(file);
      char[] buffer = new char[(int)file.length()];
      in.read(buffer);
      contents = new String(buffer);
    }
    finally
    {
      if (in != null)
      {
        in.close();
      }
    }

    Matcher matcher = PATTERN.matcher(contents);
    if (matcher.matches())
    {
      System.out.println("Modified: " + file.getPath());

      String keepProlog = matcher.group(1);
      String keepMiddle = matcher.group(3);
      String replaceWith = matcher.group(5);
      String keepEpilog = matcher.group(6);

      FileWriter out = null;

      try
      {
        out = new FileWriter(file);
        BufferedWriter writer = new BufferedWriter(out);
        writer.write(keepProlog);
        writer.write("<A NAME=\"package_description\"><!-- --></A>" + NL);
        writer.write(replaceWith);
        writer.write(keepMiddle);
        writer.write(keepEpilog);
        writer.flush();
      }
      finally
      {
        if (out != null)
        {
          out.close();
        }
      }
    }
  }
}

Back to the top