Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Rename irregularly changed classes (#31)
Browse files Browse the repository at this point in the history
This change updates package paths for the classes Range and PropertyId,
which do not follow the standard pattern of prepending v7.

Fixes #27, fixes #30
  • Loading branch information
hesara authored and ahie committed Apr 19, 2017
1 parent e1cd1c3 commit f7d41ff
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
48 changes: 35 additions & 13 deletions src/main/java/com/vaadin/framework8/migrate/Migrate.java
@@ -1,7 +1,5 @@
package com.vaadin.framework8.migrate;

import org.apache.commons.io.IOUtils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -10,7 +8,9 @@
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -20,6 +20,8 @@
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

import org.apache.commons.io.IOUtils;

public class Migrate {

private static final String VERSION = "-version=";
Expand All @@ -28,6 +30,7 @@ public class Migrate {
private static Set<String> sharedV7Classes;
private static Set<String> serverV7UIClasses;
private static Set<String> clientV7Classes;
private static Map<String, String> specialRenames;

public static void main(String[] args) throws Exception {
String version = "8.0.0.beta1";
Expand Down Expand Up @@ -64,6 +67,12 @@ public static void main(String[] args) throws Exception {
+ sharedV7Classes.size() + " classes, including "
+ serverV7UIClasses.size() + " UI classes");

specialRenames = new HashMap<>();
specialRenames.put("com.vaadin.data.fieldgroup.PropertyId",
"com.vaadin.annotations.PropertyId");
specialRenames.put("com.vaadin.shared.ui.grid.Range",
"com.vaadin.shared.Range");

File projectRoot = new File(".");
AtomicInteger javaCount = new AtomicInteger(0);
AtomicInteger htmlCount = new AtomicInteger(0);
Expand Down Expand Up @@ -92,7 +101,7 @@ private static void findV7Classes(String jarFilename, Set<String> target)
}

private static void migrateFiles(File directory, AtomicInteger javaCount,
AtomicInteger htmlCount, String version) {
AtomicInteger htmlCount, String version) {
assert directory.isDirectory();

for (File f : directory.listFiles()) {
Expand Down Expand Up @@ -138,8 +147,10 @@ private static Optional<String> getVaadin7Class(ZipEntry entry) {

private static void migrateJava(File f) throws IOException {
String javaFile = IOUtils.toString(f.toURI(), StandardCharsets.UTF_8);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(f));
OutputStreamWriter output = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
try (OutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(f));
OutputStreamWriter output = new OutputStreamWriter(outputStream,
StandardCharsets.UTF_8)) {
IOUtils.write(modifyJava(javaFile), output);
}
}
Expand All @@ -159,16 +170,27 @@ private static String modifyJava(String javaFile) {

String comvaadinClass = v7Class.replace("com.vaadin.v7.",
"com.vaadin.");
javaFile = javaFile.replace("import " + comvaadinClass + ";",
"import " + v7Class + ";");
javaFile = javaFile.replace("extends " + comvaadinClass + " ",
"extends " + v7Class + " ");
javaFile = javaFile.replace("implements " + comvaadinClass + " ",
"implements " + v7Class + " ");
javaFile = javaFile.replace("throws " + comvaadinClass + " ",
"throws " + v7Class + " ");
javaFile = performReplacement(javaFile, comvaadinClass, v7Class);
}

for (Map.Entry<String, String> rename : specialRenames.entrySet()) {
javaFile = performReplacement(javaFile, rename.getKey(),
rename.getValue());
}

return javaFile;
}

private static String performReplacement(String javaFile,
String comvaadinClass, String v7Class) {
javaFile = javaFile.replace("import " + comvaadinClass + ";",
"import " + v7Class + ";");
javaFile = javaFile.replace("extends " + comvaadinClass + " ",
"extends " + v7Class + " ");
javaFile = javaFile.replace("implements " + comvaadinClass + " ",
"implements " + v7Class + " ");
javaFile = javaFile.replace("throws " + comvaadinClass + " ",
"throws " + v7Class + " ");
return javaFile;
}

Expand Down
4 changes: 2 additions & 2 deletions test-projects/random-files/pom.xml
Expand Up @@ -14,8 +14,8 @@
</prerequisites>

<properties>
<vaadin.version>8.0.0.beta1</vaadin.version>
<vaadin.plugin.version>8.0.0.beta1</vaadin.plugin.version>
<vaadin.version>8.0.5</vaadin.version>
<vaadin.plugin.version>8.0.5</vaadin.plugin.version>
<jetty.plugin.version>9.3.9.v20160517</jetty.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
@@ -0,0 +1,39 @@
package com.vaadin.random.files;

import com.vaadin.data.fieldgroup.PropertyId;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;

public class LabelModes extends com.vaadin.ui.VerticalLayout {

@PropertyId("mine")
public Label myLabel;

protected void initializeComponents() {

Label l;
l = new Label(
"This is an undefined wide label with default content mode");
l.setWidth(null);
addComponent(l);

l = new Label(
"This label contains\nnewlines and spaces\nbut is in\ndefault content mode");
l.setWidth(null);
addComponent(l);

l = new Label(
"This label contains\nnewlines and spaces\nand is in\npreformatted mode");
l.setContentMode(ContentMode.PREFORMATTED);
l.setWidth(null);
addComponent(l);

l = new Label(
"This label contains\nnewlines and spaces\nand is in\nhtml mode");
l.setContentMode(ContentMode.HTML);
l.setWidth(null);
addComponent(l);

}

}

0 comments on commit f7d41ff

Please sign in to comment.