Skip to content

Commit 6db37f3

Browse files
author
mgricken
committed
Changed default project file extension to .drjava. Fixed remote.
git-svn-id: file:///tmp/test-svn/trunk@4951 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent ec122c4 commit 6db37f3

File tree

9 files changed

+98
-108
lines changed

9 files changed

+98
-108
lines changed

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 17 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ public class DrJava {
8080
* connecting to an already running instance. */
8181
static volatile boolean _forceNewInstance = false;
8282

83+
/** true if the files that were specified on the command line contain project files */
84+
static volatile boolean _filesToOpenContainProjectFiles = false;
85+
8386
/** Time in millisecond before restarting DrJava to change the heap size, etc. is deemed a success. */
8487
private static final int WAIT_BEFORE_DECLARING_SUCCESS = 5000;
8588

@@ -122,14 +125,10 @@ public static void main(final String[] args) {
122125
if (!_forceNewInstance &&
123126
DrJava.getConfig().getSetting(edu.rice.cs.drjava.config.OptionConstants.REMOTE_CONTROL_ENABLED) &&
124127
(_filesToOpen.size() > 0)) {
125-
// try {
126-
// boolean ret = RemoteControlClient.openFile(null);
127-
if (! RemoteControlClient.isServerRunning()) {
128+
if (!RemoteControlClient.isServerRunning()) {
128129
// server not running, display splash screen
129130
new SplashScreen().flash();
130131
}
131-
// }
132-
// catch(IOException ioe) { /* ignore */ }
133132
}
134133
else {
135134
// either forcing new instance or no files specified, display splash screen
@@ -300,6 +299,19 @@ else if (arg.equals("-help") || arg.equals("-?")) {
300299
else {
301300
// this is the first file to open, do not consume
302301
--argIndex;
302+
303+
// check if any of the files to open is a project file
304+
_filesToOpenContainProjectFiles = false;
305+
for (int tempIndex = argIndex; tempIndex < len; ++tempIndex) {
306+
String currFileName = args[tempIndex];
307+
boolean isProjectFile =
308+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
309+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
310+
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION);
311+
_filesToOpenContainProjectFiles |= isProjectFile;
312+
}
313+
// if a project file was specified, force a new instance
314+
if (_filesToOpenContainProjectFiles) _forceNewInstance = true;
303315
break;
304316
}
305317
}
@@ -345,73 +357,6 @@ static void displayUsage() {
345357
System.out.println(" -D<name>[=<value>] set a Java property for the master DrJava JVM");
346358
}
347359

348-
// /** Prompts the user that the location of tools.jar needs to be specified to be able to use the compiler and/or the
349-
// * debugger.
350-
// * @param needCompiler whether DrJava needs tools.jar for a compiler
351-
// * @param needDebugger whether DrJava needs tools.jar for the debugger
352-
// */
353-
// public static void promptForToolsJar(boolean needCompiler, boolean needDebugger) {
354-
// File selectedFile = getConfig().getSetting(JAVAC_LOCATION);
355-
// String selectedVersion = _getToolsJarVersion(selectedFile);
356-
//
357-
// final String[] text;
358-
// if (selectedVersion==null) {
359-
// text = new String[] {
360-
// "DrJava cannot find a 'tools.jar' file for the version of Java ",
361-
// "that is being used to run DrJava (Java version "+System.getProperty("java.version")+").",
362-
// "Would you like to specify the location of the requisite 'tools.jar' file?",
363-
// "If you say 'No', DrJava might be unable to compile or debug Java programs."
364-
// };
365-
// }
366-
// else {
367-
// text = new String[] {
368-
// "DrJava cannot find a 'tools.jar' file for the version of Java ",
369-
// "that is being used to run DrJava (Java version "+System.getProperty("java.version")+").",
370-
// "The file you have selected appears to be for version "+selectedVersion+".",
371-
// "Would you like to specify the location of the requisite 'tools.jar' file?",
372-
// "If you say 'No', DrJava might be unable to compile or debug Java programs.)"
373-
// };
374-
// }
375-
//
376-
// int result = JOptionPane.showConfirmDialog(null, text, "Locate 'tools.jar'?", JOptionPane.YES_NO_OPTION);
377-
//
378-
// if (result == JOptionPane.YES_OPTION) {
379-
// JFileChooser chooser = new JFileChooser();
380-
// chooser.setFileFilter(new ClassPathFilter() {
381-
// public boolean accept(File f) {
382-
// if (f.isDirectory()) return true;
383-
// String ext = getExtension(f);
384-
// return ext != null && ext.equals("jar");
385-
// }
386-
// public String getDescription() { return "Jar Files"; }
387-
// });
388-
//
389-
// // Loop until we find a good tools.jar or the user gives up
390-
// do {
391-
// if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
392-
// File jar = chooser.getSelectedFile();
393-
//
394-
// if (jar != null) {
395-
// // set the tools.jar property
396-
// getConfig().setSetting(JAVAC_LOCATION, jar);
397-
//
398-
// // Adjust if we needed a compiler
399-
// if (needCompiler && classLoadersCanFind(TEST_COMPILER_CLASS)) needCompiler = false;
400-
//
401-
// // Adjust if we need a debugger
402-
// if (needDebugger && classLoadersCanFind(TEST_DEBUGGER_CLASS)) needDebugger = false;
403-
// }
404-
// }
405-
//// Utilities.showDebug("need Compiler = " + needCompiler + "; needDebugger = " + needDebugger);
406-
// }
407-
// while ((needCompiler || needDebugger) && _userWantsToPickAgain());
408-
//
409-
// // Save config with good tools.jar if available
410-
// if ((! needCompiler) && (! needDebugger)) _saveConfig();
411-
// }
412-
// }
413-
414-
415360
/** Switches the config object to use a custom config file. Ensures that Java source files aren't
416361
* accidentally used.
417362
*/

drjava/src/edu/rice/cs/drjava/DrJavaRoot.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ private static void _openCommandLineFiles(final MainFrame mf, String[] filesToOp
246246
currFileName = currFileName.substring(0,pathSepIndex);
247247
}
248248

249-
boolean isProjectFile = currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
249+
boolean isProjectFile =
250+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
251+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
250252
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION);
251253
final File file = new File(currFileName).getAbsoluteFile();
252254
FileOpenSelector command = new FileOpenSelector() {

drjava/src/edu/rice/cs/drjava/RemoteControlClient.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
public class RemoteControlClient {
4747
/** true if a DrJava remote control server is running.
4848
*/
49-
protected static boolean _serverRunning = false;
49+
protected static Boolean _serverRunning = null;
5050

5151
/** Contains the name of the user running the server, or is null if no server is running.
5252
*/
@@ -59,7 +59,15 @@ public class RemoteControlClient {
5959
/** Return true if a DrJava remote control server is running.
6060
* @return true if running
6161
*/
62-
public static boolean isServerRunning() { return _serverRunning; }
62+
public static synchronized boolean isServerRunning() {
63+
if (_serverRunning==null) {
64+
try {
65+
openFile(null);
66+
}
67+
catch(IOException e) { _serverRunning = false; }
68+
}
69+
return _serverRunning;
70+
}
6371

6472
/** Return the name of the user running the server, or null if no server is running.
6573
* @return user name or null
@@ -70,7 +78,7 @@ public class RemoteControlClient {
7078
* @param f file, or null to just test if a server is running.
7179
* @return true if file could be opened
7280
*/
73-
public static boolean openFile(File f) throws IOException {
81+
public static synchronized boolean openFile(File f) throws IOException {
7482
try {
7583
// get a datagram socket
7684
DatagramSocket socket = new DatagramSocket();

drjava/src/edu/rice/cs/drjava/RemoteControlServer.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363
public final class RemoteControlServer {
6464
/** Prefix of a legitimate query by a client. */
6565
public static final String QUERY_PREFIX = "DrJava Remote Control?";
66-
66+
6767
/** Prefix of a legitimate response by this server. */
6868
public static final String RESPONSE_PREFIX = "DrJava Remote Control ";
69-
69+
7070
/** Prefix of a legitimate response by this server, including the user name. */
7171
public static final String RESPONSE_PREFIX_WITH_USER = RESPONSE_PREFIX+System.getProperty("user.name")+"!";
72-
72+
7373
/** Create a new remote control server, running in its own daemon thread.
7474
* @param frame main frame
7575
*/
@@ -104,7 +104,7 @@ public RCServerThread(String name, MainFrame frame) throws IOException {
104104
_frame = frame;
105105
socket = new DatagramSocket(DrJava.getConfig().getSetting(OptionConstants.REMOTE_CONTROL_PORT));
106106
}
107-
107+
108108
/**
109109
* Main method of the thread. It loops indefinitely, waiting for queries.
110110
* Since this is a daemon thread, it will get shut down at the end.
@@ -119,7 +119,7 @@ public void run() {
119119
socket.receive(packet);
120120

121121
String request = new String(packet.getData(), 0, packet.getLength());
122-
122+
123123
// check if it was a legitimate query
124124
if (request.startsWith(QUERY_PREFIX)) {
125125
// construct response
@@ -144,19 +144,24 @@ public void run() {
144144
}
145145

146146
final File f = new File(request);
147-
148147
if (f.exists()) {
149-
String currFileName = f.getName();
150-
if (currFileName.endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION)) {
151-
MainFrame.openExtProcessFile(f);
152-
}
153-
else {
154-
FileOpenSelector openSelector = new FileOpenSelector() {
155-
public File[] getFiles() throws OperationCanceledException {
156-
return new File[] { f };
157-
}
158-
};
159-
if (_frame != null) {
148+
String currFileName = f.getName();
149+
if (currFileName.endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION)) {
150+
MainFrame.openExtProcessFile(f);
151+
}
152+
else {
153+
FileOpenSelector openSelector = new FileOpenSelector() {
154+
public File[] getFiles() throws OperationCanceledException {
155+
return new File[] { f };
156+
}
157+
};
158+
if (_frame != null) {
159+
if (currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
160+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
161+
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION)) {
162+
_frame.openProject(openSelector);
163+
}
164+
else {
160165
_frame.open(openSelector);
161166
if (lineNo>=0) {
162167
final int l = lineNo;
@@ -166,6 +171,7 @@ public File[] getFiles() throws OperationCanceledException {
166171
}
167172
}
168173
}
174+
}
169175
}
170176
}
171177
else {
@@ -178,7 +184,7 @@ public File[] getFiles() throws OperationCanceledException {
178184
InetAddress address = packet.getAddress();
179185
int port = packet.getPort();
180186
packet = new DatagramPacket(buf, buf.length, address, port);
181-
187+
182188
socket.send(packet);
183189
}
184190
}

drjava/src/edu/rice/cs/drjava/config/OptionConstants.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public interface OptionConstants {
8383
public static final String OLD_PROJECT_FILE_EXTENSION = ".pjt";
8484

8585
/** The extension for a DrJava project file */
86-
public static final String PROJECT_FILE_EXTENSION = ".xml";
86+
public static final String PROJECT_FILE_EXTENSION = ".drjava";
87+
88+
/** The alternative extension for a DrJava project file */
89+
public static final String PROJECT_FILE_EXTENSION2 = ".xml";
8790

8891
/** The extension for stand-alone DrJava external process file. */
8992
public static final String EXTPROCESS_FILE_EXTENSION = ".djapp";

drjava/src/edu/rice/cs/drjava/project/ProjectFileIR.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public interface ProjectFileIR {
119119
public void setAutoRefreshStatus(boolean b);
120120

121121
/**
122-
* The version of dr java that created this project (as determined from its serialization as a .pjt or .xml file)
122+
* The version of dr java that created this project (as determined from its serialization as a .pjt or .drjava or .xml file)
123123
*
124124
* @return The version string, if known, or "unknown" otherwise.
125125
*/

drjava/src/edu/rice/cs/drjava/project/ProjectFileParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public ProjectFileIR parse(File projFile) throws IOException, FileNotFoundExcept
9494

9595
ProjectFileIR pfir = new ProjectProfile(projFile);
9696

97-
//We don't store version information in .pjt files. Yet another reason to use the .xml format.
97+
//We don't store version information in .pjt files. Yet another reason to use the .drjava or .xml format.
9898
pfir.setDrJavaVersion("unknown");
9999

100100
try { for (SEList exp : forest) evaluateExpression(exp, pfir, new DocFileListVisitor(_parent)); }

drjava/src/edu/rice/cs/drjava/ui/EditExternalDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public boolean accept(File f) {
131131
f.getPath().endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION);
132132
}
133133
public String getDescription() {
134-
return "DrJava External Process Files (*"+PROJECT_FILE_EXTENSION+", *"+OLD_PROJECT_FILE_EXTENSION+")";
134+
return "DrJava External Process Files (*"+EXTPROCESS_FILE_EXTENSION+")";
135135
}
136136
};
137137

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,16 @@ public class MainFrame extends SwingFrame implements ClipboardOwner, DropTargetL
284284
/** Filter for regular java files (.java and .j). */
285285
private final javax.swing.filechooser.FileFilter _javaSourceFilter = new JavaSourceFilter();
286286

287-
/** Filter for drjava project files (.xml and .pjt) */
287+
/** Filter for drjava project files (.drjava and .xml and .pjt) */
288288
private final javax.swing.filechooser.FileFilter _projectFilter = new javax.swing.filechooser.FileFilter() {
289289
public boolean accept(File f) {
290290
return f.isDirectory() ||
291291
f.getPath().endsWith(PROJECT_FILE_EXTENSION) ||
292+
f.getPath().endsWith(PROJECT_FILE_EXTENSION2) ||
292293
f.getPath().endsWith(OLD_PROJECT_FILE_EXTENSION);
293294
}
294295
public String getDescription() {
295-
return "DrJava Project Files (*"+PROJECT_FILE_EXTENSION+", *"+OLD_PROJECT_FILE_EXTENSION+")";
296+
return "DrJava Project Files (*"+PROJECT_FILE_EXTENSION+", *"+PROJECT_FILE_EXTENSION2+", *"+OLD_PROJECT_FILE_EXTENSION+")";
296297
}
297298
};
298299

@@ -4968,11 +4969,11 @@ private void _newProject() {
49684969

49694970
if (projectFile == null || projectFile.getParentFile() == null) { return; }
49704971
String fileName = projectFile.getName();
4971-
// ensure that saved file has extesion ".xml"
4972-
if (! fileName.endsWith(".xml")) {
4972+
// ensure that saved file has extension ".drjava"
4973+
if (! fileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION)) {
49734974
int lastIndex = fileName.lastIndexOf(".");
4974-
if (lastIndex == -1) projectFile = new File (projectFile.getAbsolutePath() + ".xml");
4975-
else projectFile = new File(projectFile.getParentFile(), fileName.substring(0, lastIndex) + ".xml");
4975+
if (lastIndex == -1) projectFile = new File (projectFile.getAbsolutePath() + OptionConstants.PROJECT_FILE_EXTENSION);
4976+
else projectFile = new File(projectFile.getParentFile(), fileName.substring(0, lastIndex) + OptionConstants.PROJECT_FILE_EXTENSION);
49764977
}
49774978
if (projectFile == null ||
49784979
projectFile.getParentFile() == null ||
@@ -5021,13 +5022,38 @@ private boolean _saveProjectAs() {
50215022

50225023
void _saveProjectHelper(File file) {
50235024
try {
5024-
if (file.getName().indexOf(".") == -1) file = new File (file.getAbsolutePath() + PROJECT_FILE_EXTENSION);
5025-
String fileName = file.getCanonicalPath();
5025+
String fileName = file.getAbsolutePath();
5026+
if (!fileName.endsWith(PROJECT_FILE_EXTENSION) &&
5027+
!fileName.endsWith(PROJECT_FILE_EXTENSION2) &&
5028+
!fileName.endsWith(OLD_PROJECT_FILE_EXTENSION)) {
5029+
// doesn't end in .drjava or .xml or .pjt
5030+
String text = "The file name does not end with a DrJava project file "+
5031+
"extension ("+PROJECT_FILE_EXTENSION+" or "+PROJECT_FILE_EXTENSION2+" or "+OLD_PROJECT_FILE_EXTENSION+"):\n"+
5032+
file.getName()+"\n"+
5033+
"Do you want to append "+PROJECT_FILE_EXTENSION+" at the end?";
5034+
5035+
Object[] options = {"Append "+PROJECT_FILE_EXTENSION, "Don't Change File Name"};
5036+
int rc = 0;
5037+
if (!Utilities.TEST_MODE) {
5038+
rc = JOptionPane.showOptionDialog(MainFrame.this, text, "Append Extension?", JOptionPane.YES_NO_OPTION,
5039+
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
5040+
}
5041+
if (rc==0) {
5042+
int lastDot = fileName.lastIndexOf('.');
5043+
if (lastDot == -1) {
5044+
file = new File(fileName + PROJECT_FILE_EXTENSION);
5045+
}
5046+
else {
5047+
file = new File(fileName.substring(0,lastDot) + PROJECT_FILE_EXTENSION);
5048+
}
5049+
}
5050+
}
5051+
fileName = file.getCanonicalPath();
50265052
if (fileName.endsWith(OLD_PROJECT_FILE_EXTENSION)) {
50275053
String text = "The project will be saved in XML format." +
5028-
"\nDo you want to change the project file's extension to \""+PROJECT_FILE_EXTENSION+"\"?";
5054+
"\nDo you want to change the project file's extension to "+PROJECT_FILE_EXTENSION+"?";
50295055

5030-
Object[] options = {"Change to \""+PROJECT_FILE_EXTENSION+"\"", "Keep \"" +
5056+
Object[] options = {"Change to "+PROJECT_FILE_EXTENSION+"", "Keep \"" +
50315057
fileName.substring(fileName.lastIndexOf('.'))+"\""};
50325058
int rc = 1;
50335059
if (!Utilities.TEST_MODE) {

0 commit comments

Comments
 (0)