32
April 05 Prof. Ismael H. F. Santos - [email protected] 1 Modulo II CheckStyle Professor Ismael H F Santos – [email protected]

April 05 Prof. Ismael H. F. Santos - [email protected] 1 Modulo II CheckStyle Professor Ismael H F Santos – [email protected]@tecgraf.puc-rio.br

Embed Size (px)

Citation preview

Page 1: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

April 05 Prof. Ismael H. F. Santos - [email protected] 1

Modulo II CheckStyle

Professor Ismael H F Santos – [email protected]

Page 2: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 2

Introduction to Apache Maven 2 Tutorial ibm developerWorks:

Bibliografia

Page 3: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 3

Ementa

Traditional Build x Maven Build

Page 4: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 4

Descrição

Ferramenta de desenvolvimento para ajudar programadores a escrever código Java aderente à um padrão de codificação.

Automatiza o processo de checagem de código Java para dispensar as pessoas desta tarefa enfadonha mas que é importante.

Ideal para projetos que queiram impor um padrão de codificação.

Page 5: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 5

Descrição

É altamente configurável e pode ser usado como apoio para quase todos os padrões de codificação.

Pode checar muitos aspectos de um código fonte.

Sua funcionalidade principal era checar trechos de layout de código.

Com a mudança da arquitetura na versão 3 mais e mais checagens para outros propósito vem sendo adicionadas.

Page 6: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 6

Descrição Atualmente fornece checagens que encontram

problemas de design de classe, código duplicado, padrões de bug.

Pode ser configurado no pom do projeto. Inclui conjuntos de regras predefinidas:

sun_checks.xml turbine_checks.xml avalon_checks.xml maven_checks.xml

Um conjunto de regras customizado pode ser especificado na configuração.

Page 7: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 7

Descrição

Metas: checkstyle:checkstyle - efetua análise Checkstyle

e gera um relatório sobre as violações checkstyle:check - efetua uma checagem de

violação contra a última passada do Checkstyle para ver se há alguma violação:

Lê o arquivo de saída do Checkstyle Conta o número de violações encontradas Exibe as violações no console

Page 8: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 8

Como baixar o plugin da Internet e instala-lo no Eclipse

Dentro do Eclipse, clique em "Help->Software Updates->Find and Install".

Page 9: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 9

Como baixar o plugin da Internet e instala-lo no Eclipse

Selecione "Search for new features to install" e clique em "Next".

Page 10: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 10

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique "New Remote Site...".

Page 11: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 11

Como baixar o plugin da Internet e instala-lo no Eclipse

Digite "Checkstyle" para o nome do plugin. Digite "http://eclipse-cs.sourceforge.net/update" para a URL. Clique em "OK".

Page 12: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 12

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique em "Finish".

Page 13: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 13

Como baixar o plugin da Internet e instala-lo no Eclipse

Aguarde a Busca.

Page 14: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 14

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique nas setas à esquerda para abrir os detalhes. Marque "Eclipse Checkstyle Plug-in" e "Maven Optional Components". Clique em "Next".

Page 15: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 15

Como baixar o plugin da Internet e instala-lo no Eclipse

Selecione "I accept the terms in the license agreements". Clique em "Next".

Page 16: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 16

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique em "Finish".

Page 17: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 17

Como baixar o plugin da Internet e instala-lo no Eclipse

Aguarde o Downloading.

Page 18: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 18

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique em "Install All".

Page 19: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 19

Como baixar o plugin da Internet e instala-lo no Eclipse

Aguarde a Instalação.

Page 20: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 20

Como baixar o plugin da Internet e instala-lo no Eclipse

Clique em "Yes" para reiniciar o Eclipse.

Page 21: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 21

Como usar no Eclipse Clique com o botão direito do mouse no pom.xml do projeto. Selecione "Run As" e clique em "4 Maven build...".

Page 22: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 22

Como usar no Eclipse Clique em "Select...".

Page 23: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 23

Como usar no Eclipse Localize "checkstyle" na lista, clique na seta à esquerda, clique em

"checkstyle" e clique em "OK".

Page 24: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 24

Como usar no Eclipse Clique em "Run".

Page 25: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 25

Como usar no Eclipse O relatório será exibido em "Console" após a linha [checkstyle:checkstyle].

Page 26: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 26

Como usar no Eclipse Clique com o botão direito do mouse no projeto. Selecione "Checkstyle" e clique em "Check Code with Checkstyle".

Page 27: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 27

Como usar no Eclipse A lista de erros aparecerá em "Problems".

Page 28: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 28

Como usar no Eclipse

Clicando duas vezes na linha de um erro, a janela de código é aberta: Uma lupa contendo informações é exibida à

esquerda das linhas com erro Linhas com erro são selecionadas em amarelo A posição do erro é marcada em azul

Veja os três exemplos que seguem:

Page 29: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 29

Como usar no Eclipse Exemplo 1:

Page 30: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 30

Como usar no Eclipse Exemplo 2:

Page 31: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 31

Como usar no Eclipse Exemplo 3:

Page 32: April 05 Prof. Ismael H. F. Santos - ismael@tecgraf.puc-rio.br 1 Modulo II CheckStyle Professor Ismael H F Santos – ismael@tecgraf.puc-rio.brismael@tecgraf.puc-rio.br

March 09 Prof. Ismael H. F. Santos 32

Fontes

http://checkstyle.sourceforge.net/index.html http://eclipse-cs.sourceforge.net/