View Javadoc
1 /* 2 AntMake 3 4 Copyright (C) 2004 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 General Public License for more details. 17 18 You should have received a copy of the GNU General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the GPL license. 23 Contact info: jsanleandro@yahoo.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 ****************************************************************************** 31 * 32 * Filename: $RCSfile: MakeRulesTemplate.java,v $ 33 * 34 * Author: Jose San Leandro Armend?riz 35 * 36 * Description: Template to generate Make-rules files. 37 * 38 * Last modified by: $Author: chous $ at $Date: 2004/02/01 17:22:14 $ 39 * 40 * File version: $Revision: 1.3 $ 41 * 42 * Project version: $Name: $ 43 * 44 * $Id: MakeRulesTemplate.java,v 1.3 2004/02/01 17:22:14 chous Exp $ 45 * 46 */ 47 package org.acmsl.antmake; 48 49 /* 50 * Importing project classes. 51 */ 52 import org.acmsl.antmake.AntMakeUtils; 53 54 /* 55 * Importing some JDK classes. 56 */ 57 import java.io.File; 58 import java.text.MessageFormat; 59 import java.util.ArrayList; 60 import java.util.Iterator; 61 import java.util.Collection; 62 63 /*** 64 * Template to generate Make-rules files. 65 * @author <a href="mailto:jsanleandro@yahoo.es" 66 >Jose San Leandro</a> 67 * @version $Revision: 1.3 $ 68 */ 69 public abstract class MakeRulesTemplate 70 { 71 /*** 72 * The default header. 73 */ 74 public static final String DEFAULT_HEADER = 75 "#\n" 76 + "# AntMake\n" 77 + "#\n" 78 + "# Copyright (C) 2004 Jose San Leandro Armend?riz\n" 79 + "# jsanleandro@yahoo.es\n" 80 + "# chousz@yahoo.com\n" 81 + "#\n" 82 + "# This library is free software; you can redistribute it and/or\n" 83 + "# modify it under the terms of the GNU General Public\n" 84 + "# License as published by the Free Software Foundation; either\n" 85 + "# version 2 of the License, or (at your option) any later " 86 + "version.\n" 87 + "#\n" 88 + "# This library is distributed in the hope that it will be " 89 + "useful,\n" 90 + "# but WITHOUT ANY WARRANTY; without even the implied warranty " 91 + "of\n" 92 + "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the " 93 + "GNU\n" 94 + "# General Public License for more details.\n" 95 + "#\n" 96 + "# You should have received a copy of the GNU General Public\n" 97 + "# License along with this library; if not, write to the Free " 98 + "Software\n" 99 + "# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA " 100 + "02111-1307 USA\n" 101 + "#\n" 102 + "# Thanks to ACM S.L. for distributing this library under the GPL " 103 + "license.\n" 104 + "# Contact info: jsanleandro@yahoo.es\n" 105 + "# Postal Address: c/Playa de Lagoa, 1\n" 106 + "# Urb. Valdecaba?as\n" 107 + "# Boadilla del monte\n" 108 + "# 28660 Madrid\n" 109 + "# Spain\n" 110 + " #################################################################" 111 + "#############\n" 112 + " #\n" 113 + " # Filename: $" + "RCSfile: $\n" 114 + " #\n" 115 + " # Author: AntMake\n" 116 + " #\n" 117 + " # Description: Defines the rules for building the project.\n" 118 + " #\n" 119 + " # Last modified by: $" + "Author: $ at $" + "Date: $\n" 120 + " #\n" 121 + " # File version: $" + "Revision: $\n" 122 + " #\n" 123 + " # Project version: $" + "Name: $\n" 124 + " #\n" 125 + " # $" + "Id: $\n" 126 + " #\n\n"; 127 128 /*** 129 * The default Make-Rules body. 130 */ 131 public static final String DEFAULT_BODY = 132 "# File suffixes\n" 133 + "SUFFIXES = .java .class\n\n" 134 + "# javadir variable\n" 135 + "javadir=$(datadir)/java/$(subdir)\n\n" 136 + "# JAVACFLAGS variable\n" 137 + "JAVACFLAGS = {0}\n\n" // The flags to javac 138 + "{1}" // The classpath declaration 139 + "JAVAROOT = $(top_builddir)\n" 140 + "GCJ = gcj\n" 141 + "JAR = fastjar\n" 142 + "LIBTOOL = $(TO_TOPDIR)/libtool\n" 143 + "#GCJFLAGS = -gdwarf-2\n" 144 + "GCJFLAGS = -g -O\n" 145 + "OFILES_DIR = $(TO_TOPDIR)/bin\n" 146 + "TO_TOPDIR = $(top_builddir)\n" 147 + "ENABLE_GCJ_COMPILED = $(EXTRA_GCJ_COMPILED) " 148 + "$(OFILES_DIR)/$(PACKAGE_FNAME).lo\n" 149 + "java_Java= $(java_BUILT) $(java_sources)\n" 150 + "GCJ_DEPS = $(java_Java) $(EXTRA_GCJ_DEPS)\n" 151 + "SOURCES = $(java_sources)\n" 152 + "DIST_SOURCES = $(SOURCES)\n" 153 + "CLEANFILES = $(java_BUILT) *.class *.stamp *.jar " 154 + "$(OFILES_DIR)/$(PACKAGE_FNAME).lo $(EXTRA_CLEAN)\n" 155 + "clean:\n" 156 + " rm -f $(CLEANFILES)\n" 157 + "\n" 158 + "DISABLE_GCJ_COMPILED_{3}1 = $(JAVA) {2}.repl\n" 159 // PROJECT NAME, project name 160 + "ENABLE_GCJ_COMPILED_{3}1 = $(OFILES_DIR)/{2}(exeext)\n" 161 // PROJECT NAME, project name 162 + "\n" 163 + "# Used when pre-processing a file using sed.\n" 164 + "DONT_EDIT_SUBS = -e ''1i//'' -e ''// DO NOT EDIT! -*- buffer-read-only: t -*-'' //\n" 165 + " -e ''1s|//.*-Java-.*|// This file is automatically generated from $@.in.|''\n" 166 + "\n" 167 + "$(OFILES_DIR)/$(PACKAGE_FNAME).lo: $(GCJ_DEPS)\n" 168 + " $(LIBTOOL) --tag=GCJ --mode=compile $(GCJ) $(GCJFLAGS) //\n" 169 + " -I$(JAVAROOT) -I$(srcdir)/$(JAVAROOT) -c //\n" 170 + " $^ $(EXTRA_GCJ_INPUTS) -o $(OFILES_DIR)/$(PACKAGE_FNAME).lo\n" 171 + "\n" 172 + "java-classes.stamp: $(java_Java)\n" 173 + " $(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) $(JAVACFLAGS) $?\n" 174 + " echo timestamp > java-classes.stamp\n"; 175 176 /*** 177 * The default javac flags. 178 */ 179 public static final String DEFAULT_JAVAC_FLAGS = ""; 180 181 /*** 182 * The default classpath declaration. 183 */ 184 public static final String DEFAULT_CLASSPATH_ENV_DECLARATION = 185 "# Classpath\n" 186 + "CLASSPATH_ENV = CLASSPATH={0}$(JAVAROOT)@pathsep@" // the classpath 187 + "$(srcdir)@filesep@$(JAVAROOT)@pathsep@$$CLASSPATH\n\n"; 188 189 /*** 190 * The default base folder variable. 191 */ 192 public static final String DEFAULT_BASE_FOLDER_VARIABLE = 193 "$(top_srcdir)"; 194 195 /*** 196 * The default path separator. 197 */ 198 public static final String DEFAULT_PATH_SEPARATOR = 199 "@pathsep@"; 200 201 /*** 202 * The default file separator. 203 */ 204 public static final String DEFAULT_FILE_SEPARATOR = 205 "@filesep@"; 206 207 /*** 208 * The header. 209 */ 210 private String m__strHeader; 211 212 /*** 213 * The Make-Rules body. 214 */ 215 private String m__strBody; 216 217 /*** 218 * The javac flags. 219 */ 220 private String m__strJavacFlags; 221 222 /*** 223 * The CLASSPATH_ENV declaration. 224 */ 225 private String m__strClasspathEnv; 226 227 /*** 228 * The base folder variable. 229 */ 230 private String m__strBaseFolder; 231 232 /*** 233 * The path separator. 234 */ 235 private String m__strPathSeparator; 236 237 /*** 238 * The file separator. 239 */ 240 private String m__strFileSeparator; 241 242 /*** 243 * The project name. 244 */ 245 private String m__strProjectName; 246 247 /*** 248 * The classpath item list. 249 */ 250 private Collection m__cClasspathItems; 251 252 /*** 253 * Builds a MakeRulesTemplate using given information. 254 * @param header the header. 255 * @param body the body. 256 * @param javacFlags the flags to Javac. 257 * @param classpathEnv the classpath env template. 258 * @param baseFolder the base folder. 259 * @param pathSeparator the path separator variable. 260 * @param fileSeparator the file separator variable. 261 * @param projectName the project name. 262 */ 263 public MakeRulesTemplate( 264 String header, 265 String body, 266 String javacFlags, 267 String classpathEnv, 268 String baseFolder, 269 String pathSeparator, 270 String fileSeparator, 271 String projectName) 272 { 273 inmutableSetHeader(header); 274 inmutableSetBody(body); 275 inmutableSetJavacFlags(javacFlags); 276 inmutableSetClasspathEnv(classpathEnv); 277 inmutableSetBaseFolder(baseFolder); 278 inmutableSetPathSeparator(pathSeparator); 279 inmutableSetFileSeparator(fileSeparator); 280 inmutableSetProjectName(projectName); 281 } 282 283 /*** 284 * Builds a MakeRulesTemplate using given information. 285 * @param projectName the project name. 286 */ 287 public MakeRulesTemplate(String projectName) 288 { 289 this( 290 DEFAULT_HEADER, 291 DEFAULT_BODY, 292 DEFAULT_JAVAC_FLAGS, 293 DEFAULT_CLASSPATH_ENV_DECLARATION, 294 DEFAULT_BASE_FOLDER_VARIABLE, 295 DEFAULT_PATH_SEPARATOR, 296 DEFAULT_FILE_SEPARATOR, 297 projectName); 298 } 299 300 /*** 301 * Specifies the header. 302 * @param header the new header. 303 */ 304 private void inmutableSetHeader(String header) 305 { 306 m__strHeader = header; 307 } 308 309 /*** 310 * Specifies the header. 311 * @param header the new header. 312 */ 313 protected void setHeader(String header) 314 { 315 inmutableSetHeader(header); 316 } 317 318 /*** 319 * Retrieves the header. 320 * @return such information. 321 */ 322 public String getHeader() 323 { 324 return m__strHeader; 325 } 326 327 /*** 328 * Specifies the body. 329 * @param body the new body. 330 */ 331 private void inmutableSetBody(String body) 332 { 333 m__strBody = body; 334 } 335 336 /*** 337 * Specifies the body. 338 * @param body the new body. 339 */ 340 protected void setBody(String body) 341 { 342 inmutableSetBody(body); 343 } 344 345 /*** 346 * Retrieves the body. 347 * @return such information. 348 */ 349 public String getBody() 350 { 351 return m__strBody; 352 } 353 354 /*** 355 * Specifies the JAVACFLAGS. 356 * @param javacFlags the new javac flags. 357 */ 358 private void inmutableSetJavacFlags(String javacFlags) 359 { 360 m__strJavacFlags = javacFlags; 361 } 362 363 /*** 364 * Specifies the JAVACFLAGS. 365 * @param javacFlags the new javac flags. 366 */ 367 protected void setJavacFlags(String javacFlags) 368 { 369 inmutableSetJavacFlags(javacFlags); 370 } 371 372 /*** 373 * Retrieves the JAVACFLAGS. 374 * @return such information. 375 */ 376 public String getJavacFlags() 377 { 378 return m__strJavacFlags; 379 } 380 381 /*** 382 * Specifies the CLASSPATH_ENV. 383 * @param classpathEnv the new classpath env. 384 */ 385 private void inmutableSetClasspathEnv(String classpathEnv) 386 { 387 m__strClasspathEnv = classpathEnv; 388 } 389 390 /*** 391 * Specifies the CLASSPATH_ENV. 392 * @param classpathEnv the new classpath env. 393 */ 394 protected void setClasspathEnv(String classpathEnv) 395 { 396 inmutableSetClasspathEnv(classpathEnv); 397 } 398 399 /*** 400 * Retrieves the CLASSPATH_ENV. 401 * @return such information. 402 */ 403 public String getClasspathEnv() 404 { 405 return m__strClasspathEnv; 406 } 407 408 /*** 409 * Specifies the base folder. 410 * @param baseFolder the new base folder. 411 */ 412 private void inmutableSetBaseFolder(String baseFolder) 413 { 414 m__strBaseFolder = baseFolder; 415 } 416 417 /*** 418 * Specifies the base folder. 419 * @param baseFolder the new base folder. 420 */ 421 protected void setBaseFolder(String baseFolder) 422 { 423 inmutableSetBaseFolder(baseFolder); 424 } 425 426 /*** 427 * Retrieves the base folder. 428 * @return such information. 429 */ 430 public String getBaseFolder() 431 { 432 return m__strBaseFolder; 433 } 434 435 /*** 436 * Specifies the path separator. 437 * @param pathSeparator the new path separator. 438 */ 439 private void inmutableSetPathSeparator(String pathSeparator) 440 { 441 m__strPathSeparator = pathSeparator; 442 } 443 444 /*** 445 * Specifies the path separator. 446 * @param pathSeparator the new path separator. 447 */ 448 protected void setPathSeparator(String pathSeparator) 449 { 450 inmutableSetPathSeparator(pathSeparator); 451 } 452 453 /*** 454 * Retrieves the path separator. 455 * @return such information. 456 */ 457 public String getPathSeparator() 458 { 459 return m__strPathSeparator; 460 } 461 462 /*** 463 * Specifies the file separator. 464 * @param fileSeparator the new file separator. 465 */ 466 private void inmutableSetFileSeparator(String fileSeparator) 467 { 468 m__strFileSeparator = fileSeparator; 469 } 470 471 /*** 472 * Specifies the file separator. 473 * @param fileSeparator the new file separator. 474 */ 475 protected void setFileSeparator(String fileSeparator) 476 { 477 inmutableSetFileSeparator(fileSeparator); 478 } 479 480 /*** 481 * Retrieves the file separator. 482 * @return such information. 483 */ 484 public String getFileSeparator() 485 { 486 return m__strFileSeparator; 487 } 488 489 /*** 490 * Specifies the project name. 491 * @param projectName the new project name. 492 */ 493 private void inmutableSetProjectName(String projectName) 494 { 495 m__strProjectName = projectName; 496 } 497 498 /*** 499 * Specifies the project name. 500 * @param projectName the new project name. 501 */ 502 protected void setProjectName(String projectName) 503 { 504 inmutableSetProjectName(projectName); 505 } 506 507 /*** 508 * Retrieves the project name. 509 * @return such information. 510 */ 511 public String getProjectName() 512 { 513 return m__strProjectName; 514 } 515 516 /*** 517 * Specifies the classes. 518 * @param classes the class list. 519 */ 520 protected void setClasspathItems(Collection classpathItems) 521 { 522 m__cClasspathItems = classpathItems; 523 } 524 525 /*** 526 * Retrieves the classpath items. 527 * @return such collection. 528 */ 529 protected Collection getClasspathItems() 530 { 531 return m__cClasspathItems; 532 } 533 534 /*** 535 * Adds a new classpath item. 536 * @param item the new item. 537 */ 538 public void addClasspathItem(String item) 539 { 540 if (item != null) 541 { 542 Collection t_cClasspathItems = getClasspathItems(); 543 544 if (t_cClasspathItems == null) 545 { 546 t_cClasspathItems = new ArrayList(); 547 setClasspathItems(t_cClasspathItems); 548 } 549 550 t_cClasspathItems.add(item); 551 } 552 } 553 554 /*** 555 * Retrieves the weaved Make-Rules file contents. 556 * @return such contents. 557 */ 558 public String toString() 559 { 560 StringBuffer t_sbResult = new StringBuffer(); 561 562 MessageFormat t_Formatter = null; 563 564 String t_strProjectName = getProjectName(); 565 566 String t_strClasspathEnv = null; 567 568 AntMakeUtils t_AntMakeUtils = AntMakeUtils.getInstance(); 569 570 Collection t_cClasspathItems = 571 getClasspathItems(); 572 573 if ( (t_AntMakeUtils != null) 574 && (t_strProjectName != null)) 575 { 576 t_sbResult.append(getHeader()); 577 578 if (t_cClasspathItems != null) 579 { 580 StringBuffer t_sbClasspathItems = 581 new StringBuffer(); 582 583 t_Formatter = 584 new MessageFormat(getClasspathEnv()); 585 586 Iterator t_itClasspathItems = 587 t_cClasspathItems.iterator(); 588 589 while (t_itClasspathItems.hasNext()) 590 { 591 String t_strClasspathItem = 592 (String) t_itClasspathItems.next(); 593 594 t_sbClasspathItems.append(getBaseFolder()); 595 t_sbClasspathItems.append( 596 t_AntMakeUtils.replaceAll( 597 t_strClasspathItem, 598 File.separator, 599 getFileSeparator())); 600 601 t_sbClasspathItems.append( 602 getPathSeparator()); 603 } 604 605 t_strClasspathEnv = 606 t_Formatter.format( 607 new Object[] { t_sbClasspathItems }); 608 } 609 610 t_Formatter = 611 new MessageFormat(getBody()); 612 613 t_sbResult.append( 614 t_Formatter.format( 615 new Object[] 616 { 617 getJavacFlags(), 618 t_strClasspathEnv, 619 t_strProjectName, 620 t_strProjectName.toUpperCase() 621 })); 622 } 623 624 return t_sbResult.toString(); 625 } 626 }

This page was automatically generated by Maven