Skip to content

Instantly share code, notes, and snippets.

@splatch
Created October 28, 2013 18:14
Show Gist options
  • Select an option

  • Save splatch/7201768 to your computer and use it in GitHub Desktop.

Select an option

Save splatch/7201768 to your computer and use it in GitHub Desktop.
Eclipse project migrator
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import org.eclipse.core.internal.localstore.SafeChunkyInputStream;
import org.eclipse.core.internal.localstore.SafeChunkyOutputStream;
public class Migrator {
/* package */static final String URI_PREFIX = "URI//"; //$NON-NLS-1$
public static void main(String[] args) throws Exception {
File file = new File("/<workspace root>/.metadata/.plugins/org.eclipse.core.resources/.projects/");
File[] projects = file.listFiles();
for (File project : projects) {
File dotLocation = new File(project, ".location");
if (!dotLocation.exists()) {
continue;
}
System.out.println("Reading " + dotLocation);
SafeChunkyInputStream input = new SafeChunkyInputStream(dotLocation, 500);
DataInputStream dataIn = new DataInputStream(input);
String location = dataIn.readUTF();
dataIn.close();
dotLocation.delete();
SafeChunkyOutputStream output = new SafeChunkyOutputStream(dotLocation);
DataOutputStream dataOut = new DataOutputStream(output);
try {
// here calculate proper location ;-)
dataOut.writeUTF(URI_PREFIX + location.toString().replaceAll(URI_PREFIX, ""));
dataOut.writeInt(0);
output.succeed();
} finally {
dataOut.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment