/*
* [JRE.java]
*
* Summary: Expand JRE reference to some sort of version.
*
* Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
*
* Licence: This software may be copied and used freely for any purpose but military.
* http://mindprod.com/contact/nonmil.html
*
* Requires: JDK 1.8+
*
* Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
*
* Version History:
* 1.8 2009-02-06 include go package in ZIP bundle.
* macro JRE macro --> 1.6 0 1.7.0
* jre1.7.0 C:\Program Files\Java\jre1.7.0
* file://localhost/C:/Program Files/Java/jre1.7.0
* 1.9 2014-08-04 addend trailing \ to path variables to idicate they are dirs.
*/
package com.mindprod.htmlmacros.macro;
import com.mindprod.htmlmacros.support.VersionFlavour;
import java.io.File;
import static com.mindprod.common18.Build.INTELLIJ_DIR;
import static com.mindprod.common18.Build.INTELLIJ_FULL_VERSION;
import static com.mindprod.common18.Build.JET_FULL_VERSION;
import static com.mindprod.common18.Build.JET_PROFILE_VERSION;
import static com.mindprod.htmlmacros.support.JDKandJREVersions.*;
import static java.lang.System.*;
/**
* Expand JRE reference to some sort of version.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.9 2014-08-04 addend trailing \ to path variables to idicate they are dirs.
* @see com.mindprod.htmlmacros.macro.JDK
* @see com.mindprod.htmlmacros.support.JDKandJREVersions
* @see JRELocation
* @since 2009
*/
public final class JRE extends Macro
{
/** how to use the macro */
/**
* how to use the macro
*/
private static final String USAGE = "\nJRE macro needs a flavour e.g macro version fullversion micro dir path url";
/**
* guts to Generate reference to the JRE.
*
* @param flavour enumeration for type of version wanted
*
* @return expanded href both to online and local.
*/
private static String expand( final VersionFlavour flavour, final File fileBeingProcessed )
{
switch ( flavour )
{
case macroversion:
return "" + JRE_MACRO_VERSION + "";
case version:
return "" + JRE_VERSION + "";
case fullversion:
return "" + JRE_FULL_VERSION + "";
case recommendedversion:
return "" + JRE_RECOMMENDED_VERSION + "";
case microversion:
return "" + JRE_MICRO_VERSION + "";
case releaseversion:
// 0
return "" + JRE_RELEASE_VERSION + "";
case dir:
return "" + JRE_DIR + "";
case path:
// C:\Program Files\Java\jre8\
return Path.decorate( JRE_PATH, false, /* is dir */ fileBeingProcessed );
case path32:
// C:\Program Files (x86)\java\jre8\
return Path.decorate( JRE_PATH32, false, /* is dir */ fileBeingProcessed );
case defaultpath:
// default dir where JRE installed
// C:\Program Files\Java\jre8\
return Path.decorate( JRE_DEFAULT_PATH, false, /*is dir*/ fileBeingProcessed );
case url:
return "" + JRE_URL + "";
case url32:
return "" + JRE_URL32 + "";
case jetprofileversion:
// 1.7.0_55
return "" + JET_PROFILE_VERSION + "";
case jetversion:
// 10.0
return "" + JET_FULL_VERSION + "";
case jetfullversion:
// jet10.0-pro-x8
return "" + JET_FULL_VERSION + "";
case ideadir:
return "" + INTELLIJ_DIR + "";
case ideafullversion:
return "" + INTELLIJ_FULL_VERSION + "";
//
case oldmacroversion:
return "" + OLD_JRE_MACRO_VERSION + "";
case oldversion:
return "" + OLD_JRE_VERSION + "";
case oldfullversion:
return "" + OLD_JRE_FULL_VERSION + "";
case oldmicroversion:
return "" + OLD_JRE_MICRO_VERSION + "";
case oldreleaseversion:
// 0
return "" + OLD_JRE_RELEASE_VERSION + "";
case olddir:
return "" + OLD_JRE_DIR + "";
case oldpath:
// C:\Program Files\Java\jre8\
return Path.decorate( OLD_JRE_PATH, false, /* is dir */ fileBeingProcessed );
case oldpath32:
// C:\Program Files (x86)\java\jre8\
return Path.decorate( OLD_JRE_PATH32, false, /* is dir */ fileBeingProcessed );
case olddefaultpath:
// default dir where JRE installed
// C:\Program Files\Java\jre8\
return Path.decorate( OLD_JRE_DEFAULT_PATH, false, /* is dir */ fileBeingProcessed );
case oldurl:
return "" + OLD_JRE_URL + "";
case oldurl32:
return "" + OLD_JRE_URL32 + "";
default:
throw new IllegalArgumentException( "JRE unknown flavour" );
}
}
/**
* Expands: Generate a reference to the JRE. See samples of use in
* mindprod/jgloss/registry.html
*
* @param parms first is degree of expansion .
* @param quiet true if want output suppressed.
* @param verbose @return expanded macro HTML
*/
public String expandMacro( String[] parms,
final boolean quiet, final boolean verbose )
{
if ( !quiet )
{
out.print( "J" );
}
if ( parms.length != 1 )
{
throw new IllegalArgumentException( USAGE );
}
String f = parms[ 0 ];
VersionFlavour flavour;
try
{
// will throw IllegalArgumentException if no match
flavour = VersionFlavour.valueOf( VersionFlavour.class, f );
}
catch ( IllegalArgumentException e )
{
throw new IllegalArgumentException( USAGE );
}
return expand( flavour, fileBeingProcessed );
}
}